package com.yycx.module.bus.provider.service.lc.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.base.utils.FlymeUtils;
import com.yycx.common.security.OpenHelper;
import com.yycx.common.security.OpenUser;
import com.yycx.common.utils.ConvertUtils;
import com.yycx.module.bus.client.entity.hy.BusErpOrder;
import com.yycx.module.bus.client.entity.hy.BusErpOrderDetails;
import com.yycx.module.bus.client.entity.lc.LcZWFZYS;
import com.yycx.module.bus.client.entity.lc.LcZWPZBH;
import com.yycx.module.bus.client.entity.lc.LcZWPZFL;
import com.yycx.module.bus.client.entity.lc.LcZWPZK;
import com.yycx.module.bus.client.enums.VoucherTypeEnum;
import com.yycx.module.bus.provider.service.hy.BusErpOrderDetailsService;
import com.yycx.module.bus.provider.service.hy.BusErpOrderService;
import com.yycx.module.bus.provider.service.hy.HyRemoteOrderService;
import com.yycx.module.bus.provider.service.lc.LcRemoteOrderService;
import com.yycx.module.bus.provider.service.lc.SyncVoucherService;
import com.yycx.module.system.client.entity.SysCompany;
import com.yycx.module.system.provider.service.SysCompanyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;


@Service
@Slf4j
public class SyncVoucherServiceImpl implements SyncVoucherService {


    @Autowired
    private LcRemoteOrderService lcRemoteOrderService;

    @Autowired
    private HyRemoteOrderService hyRemoteOrderService;

    @Lazy
    @Autowired
    private BusErpOrderDetailsService busErpOrderDetailsService;

    @Lazy
    @Autowired
    private BusErpOrderService busErpOrderService;

    @Autowired
    private SysCompanyService busCwErpService;

    @Value("${yycx.lcApi:http://192.168.50.216/cwbase/api/GS7VoucherGenerateHandler.ashx}")
    private String lcApi;

    /**
     * 是否是线上模式
     */
    private  Boolean isOnline=true;

    @Override
    @Async("voucherExecutor")
    public void createVoucher(Long companyId, String dbName, String code, List<String> orderNos, String orderType, OpenUser user, String date) {
        String currentDay = StrUtil.isNotEmpty(date) ? date : DatePattern.NORM_DATE_FORMAT.format(DateUtil.date());
        try {
            List<BusErpOrderDetails> detailsList = new ArrayList<>();
            if (VoucherTypeEnum.Cg.getCode().equals(Integer.valueOf(orderType))) {
                List<EntityMap> orderDetailList = hyRemoteOrderService.buyOrderDetailList(dbName, null, orderNos);
                orderDetailList.forEach(item -> {
                    BusErpOrderDetails busErpOrderDetails = BeanUtil.fillBeanWithMap(item, new BusErpOrderDetails(), false);
                    busErpOrderDetails.setOrderType(VoucherTypeEnum.Cg.getCode());
                    busErpOrderDetails.setErpDbName(dbName);
                    busErpOrderDetails.setHyDwCode(code);
                    busErpOrderDetails.setOrderId(IdWorker.getIdStr());
                    detailsList.add(busErpOrderDetails);
                });
            }
            if (VoucherTypeEnum.Xs.getCode().equals(Integer.valueOf(orderType))) {
                List<EntityMap> orderDetailList = hyRemoteOrderService.saleOrderDetailList(dbName, null, orderNos);
                orderDetailList.forEach(item -> {
                    BusErpOrderDetails busErpOrderDetails = BeanUtil.fillBeanWithMap(item, new BusErpOrderDetails(), false);
                    busErpOrderDetails.setOrderType(VoucherTypeEnum.Xs.getCode());
                    busErpOrderDetails.setErpDbName(dbName);
                    busErpOrderDetails.setHyDwCode(code);
                    busErpOrderDetails.setOrderId(IdWorker.getIdStr());
                    detailsList.add(busErpOrderDetails);
                });
            }
            if (VoucherTypeEnum.Cb.getCode().equals(Integer.valueOf(orderType))) {
                List<EntityMap> orderDetailList = hyRemoteOrderService.saleCostDetailList(dbName, null, orderNos);
                orderDetailList.forEach(item -> {
                    BusErpOrderDetails busErpOrderDetails = BeanUtil.fillBeanWithMap(item, new BusErpOrderDetails(), false);
                    busErpOrderDetails.setOrderType(VoucherTypeEnum.Cb.getCode());
                    busErpOrderDetails.setErpDbName(dbName);
                    busErpOrderDetails.setHyDwCode(code);
                    busErpOrderDetails.setOrderId(IdWorker.getIdStr());
                    detailsList.add(busErpOrderDetails);
                });
            }
            if (VoucherTypeEnum.Yp.getCode().equals(Integer.valueOf(orderType))) {
                List<EntityMap> orderDetailList = hyRemoteOrderService.saleOrderDetailList(dbName, null, orderNos);
                orderDetailList.forEach(item -> {
                    BusErpOrderDetails busErpOrderDetails = BeanUtil.fillBeanWithMap(item, new BusErpOrderDetails(), false);
                    busErpOrderDetails.setOrderType(VoucherTypeEnum.Yp.getCode());
                    busErpOrderDetails.setErpDbName(dbName);
                    busErpOrderDetails.setOrderId(IdWorker.getIdStr());
                    busErpOrderDetails.setHyDwCode(code);
                    detailsList.add(busErpOrderDetails);
                });
            }
            Map<String, List<BusErpOrderDetails>> collect = detailsList.stream().collect(Collectors.groupingBy(BusErpOrderDetails::getOrderNo));
            for (String orderNo : collect.keySet()) {
                List<BusErpOrderDetails> erpOrderDetails = collect.get(orderNo);
                insertZWPZ(companyId, erpOrderDetails, currentDay, orderNo,orderNos, user, orderType);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    public void mergeVoucher(Long companyId, String dbName, String code, List<String> orderNos, String orderType, OpenUser user, String date) {
        String currentDay = StrUtil.isNotEmpty(date) ? date : DatePattern.NORM_DATE_FORMAT.format(DateUtil.date());
        try {
            String orderNo = String.join(",", orderNos);
            List<BusErpOrderDetails> detailsList = new ArrayList<>();
            if (VoucherTypeEnum.Cg.getCode().equals(Integer.valueOf(orderType))) {
                List<EntityMap> orderDetailList = hyRemoteOrderService.buyOrderDetailList(dbName, null, orderNos);
                orderDetailList.forEach(item -> {
                    BusErpOrderDetails busErpOrderDetails = BeanUtil.fillBeanWithMap(item, new BusErpOrderDetails(), false);
                    busErpOrderDetails.setOrderType(VoucherTypeEnum.Cg.getCode());
                    busErpOrderDetails.setErpDbName(dbName);
                    busErpOrderDetails.setHyDwCode(code);
                    busErpOrderDetails.setOrderId(IdWorker.getIdStr());
                    detailsList.add(busErpOrderDetails);
                });
            }
            if (VoucherTypeEnum.Xs.getCode().equals(Integer.valueOf(orderType))) {
                List<EntityMap> orderDetailList = hyRemoteOrderService.saleOrderDetailList(dbName, null, orderNos);
                orderDetailList.forEach(item -> {
                    BusErpOrderDetails busErpOrderDetails = BeanUtil.fillBeanWithMap(item, new BusErpOrderDetails(), false);
                    busErpOrderDetails.setOrderType(VoucherTypeEnum.Xs.getCode());
                    busErpOrderDetails.setErpDbName(dbName);
                    busErpOrderDetails.setHyDwCode(code);
                    busErpOrderDetails.setOrderId(IdWorker.getIdStr());
                    detailsList.add(busErpOrderDetails);
                });
            }
            if (VoucherTypeEnum.Cb.getCode().equals(Integer.valueOf(orderType))) {
                List<EntityMap> orderDetailList = hyRemoteOrderService.saleCostDetailList(dbName, null, orderNos);
                orderDetailList.forEach(item -> {
                    BusErpOrderDetails busErpOrderDetails = BeanUtil.fillBeanWithMap(item, new BusErpOrderDetails(), false);
                    busErpOrderDetails.setOrderType(VoucherTypeEnum.Cb.getCode());
                    busErpOrderDetails.setErpDbName(dbName);
                    busErpOrderDetails.setHyDwCode(code);
                    busErpOrderDetails.setOrderId(IdWorker.getIdStr());
                    detailsList.add(busErpOrderDetails);
                });
            }
            if (VoucherTypeEnum.Yp.getCode().equals(Integer.valueOf(orderType))) {
                List<BusErpOrderDetails> orderDetailList = busErpOrderDetailsService.selectListByOrderNos(dbName, orderNos);
                orderDetailList.forEach(item -> {
                    item.setOrderType(VoucherTypeEnum.Yp.getCode());
                    item.setErpDbName(dbName);
                    item.setOrderId(IdWorker.getIdStr());
                    item.setHyDwCode(code);
                    detailsList.add(item);
                });
            }
            insertZWPZ(companyId, detailsList, currentDay, orderNo,orderNos, user, orderType);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    public void monthVoucher(Long companyId, String dbName, String code, List<String> orderNos, String orderType, OpenUser user, String day) {
        String currentMonth = DatePattern.NORM_MONTH_FORMAT.format(DateUtil.date());
        try {
            Map params = new HashMap();
            params.put("dbName", dbName);
            params.put("month", currentMonth);
            String orderNo = "";
            List<BusErpOrderDetails> detailsList = new ArrayList<>();

            if (VoucherTypeEnum.Xs.getCode().equals(Integer.valueOf(orderType))) {

                List<EntityMap> list = hyRemoteOrderService.monthOrderList(params);
                orderNos = list.stream().map(a -> a.get("orderNo").toString()).collect(Collectors.toList());
                orderNo = String.join(",", orderNos);

                List<EntityMap> orderDetailList = hyRemoteOrderService.saleOrderDetailList(dbName, null, orderNos);
                orderDetailList.forEach(item -> {
                    BusErpOrderDetails busErpOrderDetails = BeanUtil.fillBeanWithMap(item, new BusErpOrderDetails(), false);
                    busErpOrderDetails.setOrderType(VoucherTypeEnum.Cg.getCode());
                    busErpOrderDetails.setErpDbName(dbName);
                    busErpOrderDetails.setOrderId(IdWorker.getIdStr());
                    busErpOrderDetails.setHyDwCode(code);
                    detailsList.add(busErpOrderDetails);
                });
            }
            if (VoucherTypeEnum.Cb.getCode().equals(Integer.valueOf(orderType))) {
                List<EntityMap> list = hyRemoteOrderService.monthOrderList(params);
                orderNos = list.stream().map(a -> a.get("orderNo").toString()).collect(Collectors.toList());
                orderNo = String.join(",", orderNos);

                List<EntityMap> orderDetailList = hyRemoteOrderService.saleCostDetailList(dbName, null, orderNos);
                orderDetailList.forEach(item -> {
                    BusErpOrderDetails busErpOrderDetails = BeanUtil.fillBeanWithMap(item, new BusErpOrderDetails(), false);
                    busErpOrderDetails.setOrderType(VoucherTypeEnum.Cb.getCode());
                    busErpOrderDetails.setErpDbName(dbName);
                    busErpOrderDetails.setOrderId(IdWorker.getIdStr());
                    busErpOrderDetails.setHyDwCode(code);
                    detailsList.add(busErpOrderDetails);
                });
            }
            if (VoucherTypeEnum.Yp.getCode().equals(Integer.valueOf(orderType))) {
                List<EntityMap> list = hyRemoteOrderService.monthOrderList(params);
                orderNos = list.stream().map(a -> a.get("orderNo").toString()).collect(Collectors.toList());
                orderNo = String.join(",", orderNos);

                List<EntityMap> orderDetailList = hyRemoteOrderService.saleCostDetailList(dbName, null, orderNos);
                orderDetailList.forEach(item -> {
                    BusErpOrderDetails busErpOrderDetails = BeanUtil.fillBeanWithMap(item, new BusErpOrderDetails(), false);
                    busErpOrderDetails.setOrderType(VoucherTypeEnum.Yp.getCode());
                    busErpOrderDetails.setErpDbName(dbName);
                    busErpOrderDetails.setOrderId(IdWorker.getIdStr());
                    busErpOrderDetails.setHyDwCode(code);
                    detailsList.add(busErpOrderDetails);
                });
            }
            insertZWPZ(companyId, detailsList, "currentDay", orderNo,orderNos, user, orderType);

        } catch (Exception e) {
            e.printStackTrace();
        }
       /* if (CollUtil.isNotEmpty(orderList)) {
            List<String> orderNo = orderList.stream().map(o -> o.get("orderNo").toString()).collect(Collectors.toList());
            syncService.mergeVoucher(orderNo, MapUtil.getStr(params, "orderType"), OpenHelper.getUser(), MapUtil.getStr(params, "day", ""));
            this.update(new UpdateWrapper<BusErpOrder>().lambda().set(BusErpOrder::getUpdateTime, DateUtil.date()).set(BusErpOrder::getOperateUser, OpenHelper.getUserId()).set(BusErpOrder::getVoucherHandleState, 2).eq(BusErpOrder::getOrderType, params.get("orderType")).in(BusErpOrder::getOrderNo, orderNo));
        }*/
    }

    @Override
    @Async("voucherExecutor")
    public void createVoucher(Long companyId, List<String> orderNos, String orderType, OpenUser user, String date) {
        String currentDay = StrUtil.isNotEmpty(date) ? date : DatePattern.NORM_DATE_FORMAT.format(DateUtil.date());
        //TODO 上线删掉
        //currentDay = "2022-10-01";
        try {
            List<BusErpOrderDetails> detailsList = busErpOrderDetailsService.list(new QueryWrapper<BusErpOrderDetails>().lambda().eq(BusErpOrderDetails::getOrderType, orderType).in(BusErpOrderDetails::getOrderNo, orderNos));
            Map<String, List<BusErpOrderDetails>> collect = detailsList.stream().collect(Collectors.groupingBy(BusErpOrderDetails::getOrderNo));
            for (String orderNo : collect.keySet()) {
                List<BusErpOrderDetails> erpOrderDetails = collect.get(orderNo);
                insertZWPZ(companyId, erpOrderDetails, currentDay, orderNo,orderNos, user, orderType);
            }
            busErpOrderService.update(new UpdateWrapper<BusErpOrder>().lambda().set(BusErpOrder::getUpdateTime, DateUtil.date()).set(BusErpOrder::getOperateUser, OpenHelper.getUserId()).set(BusErpOrder::getVoucherHandleState, 1).eq(BusErpOrder::getOrderType, orderType).in(BusErpOrder::getOrderNo, orderNos));
        } catch (Exception e) {
            e.printStackTrace();
            busErpOrderService.update(new UpdateWrapper<BusErpOrder>().lambda().set(BusErpOrder::getVoucher, e.getMessage()).set(BusErpOrder::getUpdateTime, DateUtil.date()).set(BusErpOrder::getOperateUser, OpenHelper.getUserId()).set(BusErpOrder::getVoucherHandleState, 3).eq(BusErpOrder::getOrderType, orderType).in(BusErpOrder::getOrderNo, orderNos));
        }

    }

    @Override
    @Async("voucherExecutor")
    public void mergeVoucher(Long companyId, List<String> orderNos, String orderType, OpenUser user, String date) {
        String currentDay = StrUtil.isNotEmpty(date) ? date : DatePattern.NORM_DATE_FORMAT.format(DateUtil.date());
        //TODO 上线删掉
        //currentDay = "2022-10-01";
        String err = "";
        try {
            String orderNo = String.join(",", orderNos);
            List<BusErpOrderDetails> busErpOrderDetailsList = busErpOrderDetailsService.list(new QueryWrapper<BusErpOrderDetails>().lambda().eq(BusErpOrderDetails::getOrderType, orderType).in(BusErpOrderDetails::getOrderNo, orderNos));
            insertZWPZ(companyId, busErpOrderDetailsList, currentDay, orderNo,orderNos, user, orderType);
            busErpOrderService.update(new UpdateWrapper<BusErpOrder>().lambda().set(BusErpOrder::getUpdateTime, DateUtil.date()).set(BusErpOrder::getOperateUser, OpenHelper.getUserId()).set(BusErpOrder::getVoucherHandleState, 1).eq(BusErpOrder::getOrderType, orderType).in(BusErpOrder::getOrderNo, orderNos));

        } catch (Exception e) {
            e.printStackTrace();
            err = e.getMessage();
            busErpOrderService.update(new UpdateWrapper<BusErpOrder>().lambda().set(BusErpOrder::getVoucher, err).set(BusErpOrder::getUpdateTime, DateUtil.date()).set(BusErpOrder::getOperateUser, OpenHelper.getUserId()).set(BusErpOrder::getVoucherHandleState, 3).eq(BusErpOrder::getOrderType, orderType).in(BusErpOrder::getOrderNo, orderNos));

        }


    }


    private void insertZWPZ(Long companyId, List<BusErpOrderDetails> erpOrderDetails, String currentDay, String orderNo, List<String> orderNos,OpenUser user, String orderType) {
        //单位
        String ZY = "";
        String dbName = erpOrderDetails.get(0).getErpDbName();
        //部门
        String BM = "";
        String BMC = "";
        //商品
        String SP = "";
        String SPBH = "";


        String DWBH = erpOrderDetails.get(0).getHyDwCode(), KJND = currentDay.split("-")[0], KJQJ = currentDay.split("-")[1];
        String PZRQ = currentDay.replaceAll("-", "");
        // 凭证号
        int PZBH = 1;
        EntityMap zwpzbh = lcRemoteOrderService.getZWPZBH(DWBH, KJND, KJQJ);
        //String PZNM = lcRemoteOrderService.getMaxPZNM() + 1 + "";
        String PZNM = "";
        if (CollUtil.isEmpty(zwpzbh)) {
            LcZWPZBH lcZWPZBH = new LcZWPZBH();
            lcZWPZBH.setZWPZBH_DWBH(DWBH);
            lcZWPZBH.setZWPZBH_KJND(KJND);
            lcZWPZBH.setZWPZBH_KJQJ(KJQJ);
            lcZWPZBH.setZWPZBH_PZZ("0");
            lcZWPZBH.setZWPZBH_PZRQ(PZRQ);
            lcZWPZBH.setCreator(user.getNickName());
            //lcZWPZBH.setCreatedTime(DateUtil.now());
            lcZWPZBH.setZWPZBH_ID(IdWorker.get32UUID());
            lcZWPZBH.setZWPZBH_PZBH(PZBH + 1);
            List<LcZWPZBH> lcZWPZBHList = new ArrayList<>();
            lcZWPZBHList.add(lcZWPZBH);
            //lcRemoteOrderService.insertZWPZBH(lcZWPZBHList);
        } else {
            Integer zwpzbh_pzbh = zwpzbh.getInt("ZWPZBH_PZBH");
            PZBH = zwpzbh_pzbh;
            //lcRemoteOrderService.changeZWPZBH(DWBH, KJND, KJQJ, PZBH + 1, PZRQ);
        }

        //String PZBHStr = String.format("%05d", PZBH);
        String PZBHStr = "";
        List<EntityMap> productList = hyRemoteOrderService.getProductByType(dbName, "生物制品");

        List<String> productCodes = productList.stream().map(i -> i.get("productCode").toString()).collect(Collectors.toList());


        if (VoucherTypeEnum.Cg.getCode().equals(Integer.valueOf(orderType)) || VoucherTypeEnum.Xs.getCode().equals(Integer.valueOf(orderType))) {
            cgxs(companyId, erpOrderDetails, currentDay, orderNo,orderNos, user, orderType, dbName, ZY, SPBH, DWBH, KJND, KJQJ, PZRQ, PZNM, PZBHStr, productCodes);
        }
        if (VoucherTypeEnum.Fk.getCode().equals(Integer.valueOf(orderType)) || VoucherTypeEnum.Sk.getCode().equals(Integer.valueOf(orderType))) {
            sfk(companyId, erpOrderDetails, currentDay, orderNo, orderNos, user, orderType, dbName, ZY, SPBH, DWBH, KJND, KJQJ, PZRQ, PZNM, PZBHStr, productCodes);
        }
        if (VoucherTypeEnum.Cb.getCode().equals(Integer.valueOf(orderType))) {
            cb(companyId, erpOrderDetails, currentDay, orderNo,orderNos, user, orderType, dbName, ZY, SPBH, DWBH, KJND, KJQJ, PZRQ, PZNM, PZBHStr, productCodes);
        }
        if (VoucherTypeEnum.Yp.getCode().equals(Integer.valueOf(orderType))) {
            yp(companyId, erpOrderDetails, currentDay, orderNo,  orderNos,user, orderType, dbName, ZY, SPBH, DWBH, KJND, KJQJ, PZRQ, PZNM, PZBHStr, productCodes);
        }


    }

    //采购销售 8.11 7:41
    void cgxs(Long companyId, List<BusErpOrderDetails> erpOrderDetails, String currentDay, String orderNo, List<String> orderNos,OpenUser user, String orderType, String dbName, String ZY, String SPBH, String DWBH, String KJND, String KJQJ, String PZRQ, String PZNM, String PZBHStr, List<String> productCodes) {

        List<BusErpOrderDetails> collect1 = erpOrderDetails.stream().filter(e -> e.getProductNum() > 0).collect(Collectors.toList());
        List<BusErpOrderDetails> collect2 = erpOrderDetails.stream().filter(e -> e.getProductNum() < 0).collect(Collectors.toList());


        String BM;
        // 记录商品
        Map<String, List<BusErpOrderDetails>> collect11 = collect1.stream().collect(Collectors.groupingBy(p -> p.getOrderId()));
        Map<String, List<BusErpOrderDetails>> collect22 = collect2.stream().collect(Collectors.groupingBy(p -> p.getOrderId()));
        int a = 0;

        BigDecimal ZJE = new BigDecimal("0");
        BigDecimal ZJEv = new BigDecimal("0");

        List<LcZWFZYS> lcZWFZYSS = new ArrayList<>();

        for (String s1 : collect11.keySet()) {

            BigDecimal DJ = new BigDecimal("0");
            BigDecimal DJv = new BigDecimal("0");
            BigDecimal WB = new BigDecimal("0");
            BigDecimal WBv = new BigDecimal("0");
            BigDecimal JE = new BigDecimal("0");
            BigDecimal JEv = new BigDecimal("0");

            int SL = 0;
            List<BusErpOrderDetails> details = collect11.get(s1);
            BigDecimal rate = new BigDecimal(1.13).setScale(2, RoundingMode.HALF_UP);
            BusErpOrderDetails busErpOrderDetails = details.get(0);

            for (BusErpOrderDetails erpOrderDetail : details) {
                if (CollUtil.isNotEmpty(productCodes) && productCodes.contains(erpOrderDetail.getProductCode())) {
                    //    生物制品的药
                    rate = new BigDecimal(1.03).setScale(2, RoundingMode.HALF_UP);
                }
                SPBH = erpOrderDetail.getProductCode();
                JE = JE.add(erpOrderDetail.getProductSaleAmount());
                SL = SL + erpOrderDetail.getProductNum();
                WB = WB.add(erpOrderDetail.getProductSaleAmount());
                DJ = erpOrderDetail.getProductPrice();
                ZJE = ZJE.add(erpOrderDetail.getProductSaleAmount());
            }
            JEv = JE.divide(rate, 2, BigDecimal.ROUND_HALF_UP);
            DJv = SL == 0 ? new BigDecimal(SL) : JEv.divide(new BigDecimal(SL), 2, BigDecimal.ROUND_HALF_UP);
            ZJEv = ZJEv.add(JE.divide(rate, 2, BigDecimal.ROUND_HALF_UP));
            ZY = busErpOrderDetails.getCompanyName().replaceAll("\\.", "");
            //BM = (Character.isLowerCase(busErpOrderDetails.getSaleManName().charAt(0)) || Character.isUpperCase(busErpOrderDetails.getSaleManName().charAt(0))) ? (busErpOrderDetails.getSaleManName().indexOf("Z") == 0 ? busErpOrderDetails.getSaleManName() : busErpOrderDetails.getDeptName()) : "销售部";
            BM = (Character.isLowerCase(busErpOrderDetails.getSaleManName().charAt(0)) || Character.isUpperCase(busErpOrderDetails.getSaleManName().charAt(0))) ? busErpOrderDetails.getSaleManName() : busErpOrderDetails.getDeptName();
            BM = BM.indexOf("商务") != -1 ? "Z" + getNumeric(BM) : BM;
            LcZWFZYS lcZWFZYS = new LcZWFZYS();
            lcZWFZYS.setZWFZYS_DWBH(DWBH);
            lcZWFZYS.setZWFZYS_PZNM(PZNM);
            lcZWFZYS.setZWFZYS_FLNM(IdWorker.get32UUID());

            lcZWFZYS.setZWFZYS_YSBH(String.format("%04d", (a + 1)));
            lcZWFZYS.setZWFZYS_KMBH("");
            // ERP 部门名称
            String bmbh = lcRemoteOrderService.getBMBH(BM, DWBH);
            bmbh = bmbh == null ? lcRemoteOrderService.getBMBH(busErpOrderDetails.getDeptCode(), DWBH) : bmbh;
            lcZWFZYS.setZWFZYS_BMBH(bmbh == null ? "" : bmbh);
            //ERP 单位名称
            String dwbh = lcRemoteOrderService.getDWBH2(ZY, DWBH);
            dwbh = dwbh == null ? lcRemoteOrderService.getDWBH(ZY, DWBH) : dwbh;

            lcZWFZYS.setZWFZYS_WLDWBH(dwbh == null ? "" : dwbh);
            lcZWFZYS.setZWFZYS_ZGBH("");
            lcZWFZYS.setZWFZYS_CPBH("");
            //ERP 商品
            String spbh = lcRemoteOrderService.getSPBH(SPBH, DWBH);
            lcZWFZYS.setZWFZYS_XMBH(spbh == null ? "" : "000000-" + spbh);
            lcZWFZYS.setZWFZYS_WBBH("01");
            lcZWFZYS.setZWFZYS_JZFX("2");
            lcZWFZYS.setZWFZYS_SL(SL);
            lcZWFZYS.setZWFZYS_DJ(DJ);
            lcZWFZYS.setZWFZYS_DJv(DJv);
            lcZWFZYS.setZWFZYS_WB(WB);
            lcZWFZYS.setZWFZYS_HL("");
            lcZWFZYS.setZWFZYS_JE(JE);
            lcZWFZYS.setZWFZYS_JEv(JEv);
            lcZWFZYS.setZWFZYS_YWRQ(PZRQ);
            lcZWFZYS.setZWFZYS_DWDZ(0);
            lcZWFZYS.setZWFZYS_SJ01(0);
            lcZWFZYS.setZWFZYS_SJ02(0);
            lcZWFZYS.setZWFZYS_SJ03(0);
            lcZWFZYS.setZWFZYS_SJ04(0);
            lcZWFZYS.setZWFZYS_SJ05(0);
            lcZWFZYS.setZWFZYS_YT(ZY + (orderNo.length() > 80 ? orderNos.size() : orderNo));
            lcZWFZYS.setZWFZYS_YHDZ(0);
            lcZWFZYS.setZWFZYS_JSRQ(PZRQ);
            lcZWFZYS.setZWFZYS_ZPDY("0");
            lcZWFZYS.setCreator("");
            //lcZWFZYS.setCreatedTime(DateUtil.now());
            lcZWFZYS.setLastModifier("");
            //lcZWFZYS.setLastModifiedTime(DateUtil.now());
            //lcZWFZYS.setZWFZYS_ID(IdWorker.get32UUID());
            lcZWFZYS.setZWFZYS_BMVersion("1");
            lcZWFZYS.setZWFZYS_WLDWVersion("1");
            lcZWFZYS.setZWFZYS_ZJDJBZ("");
            lcZWFZYS.setZWFZYS_KJLX("0");
            lcZWFZYSS.add(lcZWFZYS);
        }

        for (String s2 : collect22.keySet()) {
            BigDecimal DJ = new BigDecimal("0");
            BigDecimal DJv = new BigDecimal("0");
            BigDecimal WB = new BigDecimal("0");
            BigDecimal WBv = new BigDecimal("0");
            BigDecimal JE = new BigDecimal("0");
            BigDecimal JEv = new BigDecimal("0");

            int SL = 0;
            List<BusErpOrderDetails> details = collect22.get(s2);
            BigDecimal rate = new BigDecimal(1.13).setScale(2, RoundingMode.HALF_UP);
            BusErpOrderDetails busErpOrderDetails = details.get(0);

            for (BusErpOrderDetails erpOrderDetail : details) {
                if (CollUtil.isNotEmpty(productCodes) && productCodes.contains(erpOrderDetail.getProductCode())) {
                    //    生物制品的药
                    rate = new BigDecimal(1.03).setScale(2, RoundingMode.HALF_UP);
                }
                SPBH = erpOrderDetail.getProductCode();
                JE = JE.add(erpOrderDetail.getProductSaleAmount());
                SL = SL + erpOrderDetail.getProductNum();
                WB = WB.add(erpOrderDetail.getProductSaleAmount());
                DJ = erpOrderDetail.getProductPrice();
                ZJE = ZJE.add(erpOrderDetail.getProductSaleAmount());
            }
            JEv = JE.divide(rate, 2, BigDecimal.ROUND_HALF_UP);
            DJv = SL == 0 ? new BigDecimal(SL) : JEv.divide(new BigDecimal(SL), 2, BigDecimal.ROUND_HALF_UP);
            ZJEv = ZJEv.add(JE.divide(rate, 2, BigDecimal.ROUND_HALF_UP));
            ZY = busErpOrderDetails.getCompanyName().replaceAll("\\.", "");
            //BM = (Character.isLowerCase(busErpOrderDetails.getSaleManName().charAt(0)) || Character.isUpperCase(busErpOrderDetails.getSaleManName().charAt(0))) ? (busErpOrderDetails.getSaleManName().indexOf("Z") == 0 ? busErpOrderDetails.getSaleManName() : busErpOrderDetails.getDeptName()) : "销售部";
            BM = (Character.isLowerCase(busErpOrderDetails.getSaleManName().charAt(0)) || Character.isUpperCase(busErpOrderDetails.getSaleManName().charAt(0))) ? busErpOrderDetails.getSaleManName() : busErpOrderDetails.getDeptName();
            BM = BM.indexOf("商务") != -1 ? "Z" + getNumeric(BM) : BM;
            LcZWFZYS lcZWFZYS = new LcZWFZYS();
            lcZWFZYS.setZWFZYS_DWBH(DWBH);
            lcZWFZYS.setZWFZYS_PZNM(PZNM);
            lcZWFZYS.setZWFZYS_FLNM(IdWorker.get32UUID());

            lcZWFZYS.setZWFZYS_YSBH(String.format("%04d", (a + 1)));
            lcZWFZYS.setZWFZYS_KMBH("");
            // ERP 部门名称
            String bmbh = lcRemoteOrderService.getBMBH(BM, DWBH);
            bmbh = bmbh == null ? lcRemoteOrderService.getBMBH(busErpOrderDetails.getDeptCode(), DWBH) : bmbh;
            lcZWFZYS.setZWFZYS_BMBH(bmbh == null ? "" : bmbh);
            //ERP 单位名称
            String dwbh = lcRemoteOrderService.getDWBH2(ZY, DWBH);
            dwbh = dwbh == null ? lcRemoteOrderService.getDWBH(ZY, DWBH) : dwbh;

            lcZWFZYS.setZWFZYS_WLDWBH(dwbh == null ? "" : dwbh);
            lcZWFZYS.setZWFZYS_ZGBH("");
            lcZWFZYS.setZWFZYS_CPBH("");
            //ERP 商品
            String spbh = lcRemoteOrderService.getSPBH(SPBH, DWBH);
            lcZWFZYS.setZWFZYS_XMBH(spbh == null ? "" : "000000-" + spbh);
            lcZWFZYS.setZWFZYS_WBBH("01");
            lcZWFZYS.setZWFZYS_JZFX("2");
            lcZWFZYS.setZWFZYS_SL(SL);
            lcZWFZYS.setZWFZYS_DJ(DJ);
            lcZWFZYS.setZWFZYS_DJv(DJv);
            lcZWFZYS.setZWFZYS_WB(WB);
            lcZWFZYS.setZWFZYS_HL("");
            lcZWFZYS.setZWFZYS_JE(JE);
            lcZWFZYS.setZWFZYS_JEv(JEv);
            lcZWFZYS.setZWFZYS_YWRQ(PZRQ);
            lcZWFZYS.setZWFZYS_DWDZ(0);
            lcZWFZYS.setZWFZYS_SJ01(0);
            lcZWFZYS.setZWFZYS_SJ02(0);
            lcZWFZYS.setZWFZYS_SJ03(0);
            lcZWFZYS.setZWFZYS_SJ04(0);
            lcZWFZYS.setZWFZYS_SJ05(0);
            lcZWFZYS.setZWFZYS_YT(ZY + (orderNo.length() > 80 ? "" : orderNo));
            lcZWFZYS.setZWFZYS_YHDZ(0);
            lcZWFZYS.setZWFZYS_JSRQ(PZRQ);
            lcZWFZYS.setZWFZYS_ZPDY("0");
            lcZWFZYS.setCreator("");
            //lcZWFZYS.setCreatedTime(DateUtil.now());
            lcZWFZYS.setLastModifier("");
            //lcZWFZYS.setLastModifiedTime(DateUtil.now());
            //lcZWFZYS.setZWFZYS_ID(IdWorker.get32UUID());
            lcZWFZYS.setZWFZYS_BMVersion("1");
            lcZWFZYS.setZWFZYS_WLDWVersion("1");
            lcZWFZYS.setZWFZYS_ZJDJBZ("");
            lcZWFZYS.setZWFZYS_KJLX("0");
            lcZWFZYSS.add(lcZWFZYS);
        }


        // 主记录
        LcZWPZK lcZWPZK = new LcZWPZK();
        lcZWPZK.setZWPZK_DWBH(DWBH);
        lcZWPZK.setZWPZK_PZNM(PZNM);
        lcZWPZK.setZWPZK_KJND(KJND);
        lcZWPZK.setZWPZK_KJQJ(KJQJ);
        lcZWPZK.setZWPZK_PZRQ(PZRQ);
        lcZWPZK.setZWPZK_PZBH(PZBHStr);
        lcZWPZK.setZWPZK_LXBH("01");
        lcZWPZK.setZWPZK_FJZS(0);
        lcZWPZK.setZWPZK_TYPE(0);
        lcZWPZK.setZWPZK_ZDR(user.getNickName());
        lcZWPZK.setSysUserID(user.getAvatar());
        lcZWPZK.setZWPZK_KJZG(" ");
        lcZWPZK.setZWPZK_FHF(0);
        lcZWPZK.setZWPZK_JZF(0);
        lcZWPZK.setZWPZK_WZF(1);
        lcZWPZK.setZWPZK_ZFF(0);
        lcZWPZK.setZWPZK_XJDQ(0);
        lcZWPZK.setZWPZK_PZZT(1);
        lcZWPZK.setZWPZK_ZDBZ(0);
        lcZWPZK.setZWPZK_TZDZS(0);
        //lcZWPZK.setZWPZK_ID(IdWorker.get32UUID());
        lcZWPZK.setZWPZK_ZY(ZY + (orderNo.length() > 80 ? "" : orderNo));
        lcZWPZK.setZWPZK_JE(ZJE);
        lcZWPZK.setCreator("");
        //lcZWPZK.setCreatedTime(DateUtil.now());
        lcZWPZK.setLastModifier("");
        //lcZWPZK.setLastModifiedTime(DateUtil.now());
        lcZWPZK.setZWPZK_DWVersion("1");
        lcZWPZK.setSecretLevelNum("0");
        lcZWPZK.setImageBarCode("");
        lcZWPZK.setImageElecVoucher("");
        lcZWPZK.setZWPZK_DYF("");
        //lcZWPZK.setZWPZK_PZKID(IdWorker.get32UUID());
        lcZWPZK.setZWPZK_ZDRBH(user.getUsername());
        //lcRemoteOrderService.insertZWPZK(lcZWPZK);

        //凭证明细
        List<LcZWPZFL> lcZWPZFLS = new ArrayList<>();
        //600101	主营业务收入-销售商品收入

        String KMBH11 = "", KMBH12 = "", KMBH13 = "";
        //器械
        if (companyId.equals(1017L)) {
            switch (orderType) {
                case "2":
                    KMBH11 = "600102";
                    KMBH12 = "22210105";
                    KMBH13 = "112202";
                    break;
                case "4":
                    KMBH11 = "140502";
                    //KMBH12 = "22210101";
                    KMBH12 = "2221010101";
                    KMBH13 = "220203";
                    break;
                default:

            }

        } else {
            switch (orderType) {
                case "2":
                    KMBH11 = "600101";
                    KMBH12 = "22210105";
                    KMBH13 = "112201";
                    break;
                case "4":
                    KMBH11 = "140501";
                    //KMBH12 = "22210101";
                    KMBH12 = "2221010101";
                    KMBH13 = "220202";
                    break;
                default:

            }
        }
        LcZWPZFL lcZWPZFL = new LcZWPZFL();
        lcZWPZFL.setZWPZFL_DWBH(DWBH);
        lcZWPZFL.setZWPZFL_PZNM(PZNM);
        //lcZWPZFL.setZWPZFL_FLNM(IdWorker.get32UUID());
        lcZWPZFL.setZWPZFL_FLBH("0001");
        lcZWPZFL.setZWPZFL_KMBH(KMBH11);
        lcZWPZFL.setZWPZFL_JSFS("");
        lcZWPZFL.setZWPZFL_ZY(ZY + (orderNo.length() > 80 ? orderNos.size() : orderNo));
        lcZWPZFL.setZWPZFL_JE(ZJEv);
        //lcZWPZFL.setZWPZFL_SL(SL);
        //lcZWPZFL.setZWPZFL_DJ(SL == 0 ? new BigDecimal(SL) : JE.divide(new BigDecimal(SL), BigDecimal.ROUND_CEILING));
        //lcZWPZFL.setZWPZFL_WB(WB);

        lcZWPZFL.setZWPZFL_SL(0);
        lcZWPZFL.setZWPZFL_DJ(new BigDecimal(0));
        lcZWPZFL.setZWPZFL_WB(ZJEv);
        lcZWPZFL.setZWPZFL_HL(1);
        lcZWPZFL.setZWPZFL_JZFX(2);

        lcZWPZFL.setZWPZFL_DFJE(ZJEv);
        lcZWPZFL.setZWPZFL_JFJE(new BigDecimal(0));
        if (VoucherTypeEnum.Cg.getCode().equals(Integer.valueOf(orderType))) {
            lcZWPZFL.setZWPZFL_JZFX(1);
            lcZWPZFL.setZWPZFL_JFJE(ZJEv);
            lcZWPZFL.setZWPZFL_DFJE(new BigDecimal(0));
        }

        lcZWPZFL.setZWPZFL_WBBH("01");
        lcZWPZFL.setZWPZFL_YHDZ("0");
        //lcZWPZFL.setZWPZFL_ID(IdWorker.get32UUID());
        lcZWPZFL.setCreator("");
        //lcZWPZFL.setCreatedTime(DateUtil.now());
        lcZWPZFL.setLastModifier("");
        //lcZWPZFL.setLastModifiedTime(DateUtil.now());
        lcZWPZFL.setZWPZFL_KJLX("0");
        lcZWPZFL.setZWPZFL_DZZD("");
        //lcZWPZFLS.add(lcZWPZFL);
        //科目辅助项
        List<LcZWFZYS> LcZWFZYSS1 = deepCopy(lcZWFZYSS);
        String finalKMBH = KMBH11;
        LcZWFZYSS1.forEach(s1 -> {
            s1.setZWFZYS_KMBH(finalKMBH);
            s1.setZWFZYS_JZFX("2");
            if (VoucherTypeEnum.Cg.getCode().equals(Integer.valueOf(orderType))) {
                s1.setZWFZYS_JZFX("1");
            }
            s1.setZWFZYS_JE(s1.getZWFZYS_JEv());
            s1.setZWFZYS_DJ(s1.getZWFZYS_DJv());
            s1.setZWFZYS_FLNM(lcZWPZFL.getZWPZFL_FLNM());
            //s1.setZWFZYS_ID(IdWorker.get32UUID());
        });

        //22210105	应交税费-应交增值税-销项税额
        LcZWPZFL lcZWPZFL2 = new LcZWPZFL();
        lcZWPZFL2.setZWPZFL_DWBH(DWBH);
        lcZWPZFL2.setZWPZFL_PZNM(PZNM);
        //lcZWPZFL2.setZWPZFL_FLNM(IdWorker.get32UUID());
        lcZWPZFL2.setZWPZFL_FLBH("0002");
        lcZWPZFL2.setZWPZFL_KMBH(KMBH12);
        lcZWPZFL2.setZWPZFL_JSFS("");
        lcZWPZFL2.setZWPZFL_ZY(ZY + (orderNo.length() > 80 ? orderNos.size(): orderNo));
        lcZWPZFL2.setZWPZFL_JE(ZJE.subtract(ZJEv).setScale(2, RoundingMode.HALF_UP));

        lcZWPZFL2.setZWPZFL_SL(0);
        //lcZWPZFL2.setZWPZFL_SL(SL);
        lcZWPZFL2.setZWPZFL_DJ(new BigDecimal(0));
        lcZWPZFL2.setZWPZFL_WB(lcZWPZFL2.getZWPZFL_JE());
        lcZWPZFL2.setZWPZFL_HL(1);
        lcZWPZFL2.setZWPZFL_JZFX(2);
        lcZWPZFL2.setZWPZFL_DFJE(lcZWPZFL2.getZWPZFL_JE());
        lcZWPZFL2.setZWPZFL_JFJE(new BigDecimal(0));
        if (VoucherTypeEnum.Cg.getCode().equals(Integer.valueOf(orderType))) {
            lcZWPZFL2.setZWPZFL_JZFX(1);
            lcZWPZFL2.setZWPZFL_JFJE(lcZWPZFL2.getZWPZFL_JE());
            lcZWPZFL2.setZWPZFL_DFJE(new BigDecimal(0));
        }
        lcZWPZFL2.setZWPZFL_WBBH("01");
        lcZWPZFL2.setZWPZFL_YHDZ("0");
        //lcZWPZFL2.setZWPZFL_ID(IdWorker.get32UUID());
        lcZWPZFL2.setCreator("");
        //lcZWPZFL2.setCreatedTime(DateUtil.now());
        lcZWPZFL2.setLastModifier("");
        //lcZWPZFL2.setLastModifiedTime(DateUtil.now());
        lcZWPZFL2.setZWPZFL_KJLX("0");
        lcZWPZFL2.setZWPZFL_DZZD("");
        //lcZWPZFLS.add(lcZWPZFL2);
        List<LcZWFZYS> LcZWFZYSS2 = new ArrayList<>();


        Map<String, List<LcZWFZYS>> bms = lcZWFZYSS.stream().filter(i -> i.getZWFZYS_BMBH() != null).collect(Collectors.groupingBy(LcZWFZYS::getZWFZYS_BMBH));
        int it = 0;
        for (String bm : bms.keySet()) {
            List<LcZWFZYS> lcZWFZYS_ = bms.get(bm);
            it++;
            LcZWFZYS lcZWFZYS = new LcZWFZYS();
            lcZWFZYS.setZWFZYS_DWBH(DWBH);
            lcZWFZYS.setZWFZYS_PZNM(PZNM);
            lcZWFZYS.setZWFZYS_FLNM(lcZWPZFL2.getZWPZFL_FLNM());
            lcZWFZYS.setZWFZYS_YSBH(String.format("%04d", (it)));
            lcZWFZYS.setZWFZYS_KMBH(KMBH12);
            // ERP 部门名称
            //String bmbh = lcRemoteOrderService.getBMBH(bm, DWBH);
            //lcZWFZYS.setZWFZYS_BMBH(bmbh == null ? "0150" : bmbh);
            lcZWFZYS.setZWFZYS_BMBH(bm);
            //ERP 单位名称
            String dwbh = lcRemoteOrderService.getDWBH2(ZY, DWBH);
            dwbh = dwbh == null ? lcRemoteOrderService.getDWBH(ZY, DWBH) : dwbh;

            lcZWFZYS.setZWFZYS_WLDWBH(dwbh == null ? "" : dwbh);

            lcZWFZYS.setZWFZYS_ZGBH("");
            lcZWFZYS.setZWFZYS_CPBH("");
            //ERP 商品
            String spbh = lcRemoteOrderService.getSPBH(SPBH, DWBH);
            lcZWFZYS.setZWFZYS_XMBH(spbh == null ? "" : "000000-" + spbh);
            lcZWFZYS.setZWFZYS_WBBH("01");
            lcZWFZYS.setZWFZYS_JZFX("2");
            if (VoucherTypeEnum.Cg.getCode().equals(Integer.valueOf(orderType))) {
                lcZWFZYS.setZWFZYS_JZFX("1");
            }
            lcZWFZYS.setZWFZYS_SL(lcZWFZYS_.stream().map(LcZWFZYS::getZWFZYS_SL).mapToInt(i -> i).sum());

            lcZWFZYS.setZWFZYS_DJ(new BigDecimal(0));
            lcZWFZYS.setZWFZYS_WB(new BigDecimal(0));
            //lcZWFZYS.setZWFZYS_DJ(new BigDecimal(lcZWFZYS_.stream().map(LcZWFZYS::getZWFZYS_DJ).mapToDouble(b -> b).sum()));
            //lcZWFZYS.setZWFZYS_WB(new BigDecimal(lcZWFZYS_.stream().map(LcZWFZYS::getZWFZYS_WB).mapToDouble(b -> b).sum()));
            lcZWFZYS.setZWFZYS_HL("");
            BigDecimal zje = new BigDecimal(0);
            BigDecimal zjev = new BigDecimal(0);
            for (LcZWFZYS zwfzys : lcZWFZYS_) {
                zje = zje.add(zwfzys.getZWFZYS_JE());
                zjev = zjev.add(zwfzys.getZWFZYS_JEv());
            }
            lcZWFZYS.setZWFZYS_JE(zje.subtract(zjev).setScale(2, RoundingMode.HALF_UP));
            lcZWFZYS.setZWFZYS_YWRQ(PZRQ);
            lcZWFZYS.setZWFZYS_DWDZ(0);
            lcZWFZYS.setZWFZYS_SJ01(0);
            lcZWFZYS.setZWFZYS_SJ02(0);
            lcZWFZYS.setZWFZYS_SJ03(0);
            lcZWFZYS.setZWFZYS_SJ04(0);
            lcZWFZYS.setZWFZYS_SJ05(0);
            lcZWFZYS.setZWFZYS_YT(ZY + (orderNo.length() > 80 ? "" : orderNo));
            lcZWFZYS.setZWFZYS_YHDZ(0);
            lcZWFZYS.setZWFZYS_JSRQ(PZRQ);
            lcZWFZYS.setZWFZYS_ZPDY("0");
            lcZWFZYS.setCreator("");
            //lcZWFZYS.setCreatedTime(DateUtil.now());
            lcZWFZYS.setLastModifier("");
            //lcZWFZYS.setLastModifiedTime(DateUtil.now());
            //lcZWFZYS.setZWFZYS_ID(IdWorker.get32UUID());
            lcZWFZYS.setZWFZYS_BMVersion("1");
            lcZWFZYS.setZWFZYS_WLDWVersion("1");
            lcZWFZYS.setZWFZYS_ZJDJBZ("");
            lcZWFZYS.setZWFZYS_KJLX("0");
            LcZWFZYSS2.add(lcZWFZYS);
        }


        //112202	应收账款-应收账款
        LcZWPZFL lcZWPZFL3 = new LcZWPZFL();
        lcZWPZFL3.setZWPZFL_DWBH(DWBH);
        lcZWPZFL3.setZWPZFL_PZNM(PZNM);
        //lcZWPZFL3.setZWPZFL_FLNM(IdWorker.get32UUID());
        lcZWPZFL3.setZWPZFL_FLBH("0003");
        //控制凭证显示顺序
        if ("112202".equals(KMBH13) || "112201".equals(KMBH13)) {
            lcZWPZFL3.setZWPZFL_FLBH("0000");
        }
        lcZWPZFL3.setZWPZFL_KMBH(KMBH13);
        lcZWPZFL3.setZWPZFL_JSFS("");
        lcZWPZFL3.setZWPZFL_ZY(ZY + (orderNo.length() > 80 ? orderNos.size() : orderNo));
        lcZWPZFL3.setZWPZFL_JE(ZJE);

        //lcZWPZFL3.setZWPZFL_SL(SL);
        lcZWPZFL3.setZWPZFL_SL(0);
        lcZWPZFL3.setZWPZFL_DJ(new BigDecimal(0));
        lcZWPZFL3.setZWPZFL_WB(ZJE);
        lcZWPZFL3.setZWPZFL_HL(1);
        lcZWPZFL3.setZWPZFL_JZFX(1);
        lcZWPZFL3.setZWPZFL_JFJE(ZJE);
        lcZWPZFL3.setZWPZFL_DFJE(new BigDecimal(0));

        if (VoucherTypeEnum.Cg.getCode().equals(Integer.valueOf(orderType))) {
            lcZWPZFL3.setZWPZFL_JZFX(2);
            lcZWPZFL3.setZWPZFL_DFJE(ZJE);
            lcZWPZFL3.setZWPZFL_JFJE(new BigDecimal(0));

        }
        lcZWPZFL3.setZWPZFL_WBBH("01");
        lcZWPZFL3.setZWPZFL_YHDZ("0");
        //lcZWPZFL3.setZWPZFL_ID(IdWorker.get32UUID());
        lcZWPZFL3.setCreator("");
        //lcZWPZFL3.setCreatedTime(DateUtil.now());
        lcZWPZFL3.setLastModifier("");
        //lcZWPZFL3.setLastModifiedTime(DateUtil.now());
        lcZWPZFL3.setZWPZFL_KJLX("0");
        lcZWPZFL3.setZWPZFL_DZZD("");
        //lcZWPZFLS.add(lcZWPZFL3);

        //List<LcZWFZYS> LcZWFZYSS3 = LcZWFZYSS.stream().collect(Collectors.toList());
        List<LcZWFZYS> LcZWFZYSS3 = deepCopy(lcZWFZYSS);
        String finalKMBH1 = KMBH13;
        LcZWFZYSS3.forEach(s3 -> {
            s3.setZWFZYS_KMBH(finalKMBH1);
            s3.setZWFZYS_JZFX("1");
            if (VoucherTypeEnum.Cg.getCode().equals(Integer.valueOf(orderType))) {
                s3.setZWFZYS_JZFX("2");
            }
            s3.setZWFZYS_FLNM(lcZWPZFL3.getZWPZFL_FLNM());
            //s3.setZWFZYS_ID(IdWorker.get32UUID());
        });
        //lcRemoteOrderService.insertZWPZFL(lcZWPZFLS);

        //lcRemoteOrderService.insertZWFZYS(LcZWFZYSS3);
        //lcRemoteOrderService.insertZWFZYS(LcZWFZYSS2);
        //lcRemoteOrderService.insertZWFZYS(LcZWFZYSS1);


        //lcZWPZK

        lcZWPZFL3.setVoucherfzhs(LcZWFZYSS3);
        lcZWPZFL2.setVoucherfzhs(LcZWFZYSS2);
        lcZWPZFL.setVoucherfzhs(LcZWFZYSS1);
        lcZWPZFLS.add(lcZWPZFL3);
        lcZWPZFLS.add(lcZWPZFL2);
        lcZWPZFLS.add(lcZWPZFL);
        lcZWPZK.setVoucherfl(lcZWPZFLS);

        JSONObject obj = JSONUtil.createObj();
        obj.set("voucherHead", lcZWPZK);

        String s = JSONUtil.toJsonStr(obj);
        System.out.println("#########################凭证参数:"+s);
        log.info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@凭证参数",s);
        String url = "http://192.168.50.216/cwbase/api/GS7VoucherGenerateHandler.ashx";
        if(isOnline) {
            //System.out.println(s);
            String result = HttpUtil.post(lcApi, s);

            //System.out.println(result);
            JSONObject jsonObject = JSONUtil.parseObj(result);
            if ("200".equals(jsonObject.getStr("code"))) {

                //jsonObject.get("data")
                String data = jsonObject.get("data").toString();

                JSONObject objData = JSONUtil.parseObj(data);
                Object savedVochers = objData.get("SavedVochers");
                int state = 0;
                String voucher = "";

                if (objData.get("FailedVochers").toString().length() > 3) {
                    savedVochers = objData.get("FailedVochers");
                    voucher = savedVochers.toString();
                    state = 3;

                } else {
                    savedVochers = savedVochers.toString().substring(savedVochers.toString().indexOf("#") + 1, savedVochers.toString().indexOf("#") + 6);
                    state = 1;
                    voucher = currentDay + " " + savedVochers;
                }


                if (VoucherTypeEnum.Xs.getCode().equals(Integer.valueOf(orderType))) {
                    hyRemoteOrderService.updateXsVocher(dbName, state, voucher, StrUtil.split(orderNo, ','));
                } else {
                    hyRemoteOrderService.updateCgVocher(dbName, state, voucher, StrUtil.split(orderNo, ','));
                }

            } else {
                if (VoucherTypeEnum.Xs.getCode().equals(Integer.valueOf(orderType))) {
                    hyRemoteOrderService.updateXsVocher(dbName, 3, "", StrUtil.split(orderNo, ','));
                } else {
                    hyRemoteOrderService.updateCgVocher(dbName, 3, "", StrUtil.split(orderNo, ','));
                }
            }
        }
    }

    //成本
    void cb(Long companyId, List<BusErpOrderDetails> busErpOrderDetailsList, String currentDay, String orderNo,List<String> orderNos, OpenUser user, String orderType, String dbName, String ZY, String SPBH, String DWBH, String KJND, String KJQJ, String PZRQ, String PZNM, String PZBHStr, List<String> productCodes) {

     /*   String DWBH = busCwErp.getCompanyCode(), KJND = currentDay.split("-")[0], KJQJ = currentDay.split("-")[1];
    String PZRQ = currentDay.replaceAll("-", "");
    // 凭证号
    int PZBH = 1;
    EntityMap zwpzbh = lcRemoteOrderService.getZWPZBH(DWBH, KJND, KJQJ);
    String PZNM = lcRemoteOrderService.getMaxPZNM() + 1 + "";
    if (CollUtil.isEmpty(zwpzbh)) {
        LcZWPZBH lcZWPZBH = new LcZWPZBH();
        lcZWPZBH.setZWPZBH_DWBH(DWBH);
        lcZWPZBH.setZWPZBH_KJND(KJND);
        lcZWPZBH.setZWPZBH_KJQJ(KJQJ);
        lcZWPZBH.setZWPZBH_PZZ("0");
        lcZWPZBH.setZWPZBH_PZRQ(PZRQ);
        lcZWPZBH.setCreator("");
        lcZWPZBH.setCreatedTime(DateUtil.now());
        lcZWPZBH.setZWPZBH_ID(IdWorker.get32UUID());
        lcZWPZBH.setZWPZBH_PZBH(PZBH);
        List<LcZWPZBH> lcZWPZBHList = new ArrayList<>();
        lcZWPZBHList.add(lcZWPZBH);
        lcRemoteOrderService.insertZWPZBH(lcZWPZBHList);
    } else {
        Integer zwpzbh_pzbh = zwpzbh.getInt("ZWPZBH_PZBH");
        PZBH = zwpzbh_pzbh + 1;
        lcRemoteOrderService.changeZWPZBH(DWBH, KJND, KJQJ, PZBH, PZRQ);
    }

    String PZBHStr = String.format("%05d", PZBH);*/
        List<LcZWFZYS> LcZWFZYSS = new ArrayList<>();

        //制证人
        //EntityMap defUserId = busErpOrderService.getDefUserId(DWBH);

        // 记录商品
        Map<String, List<BusErpOrderDetails>> collect = busErpOrderDetailsList.stream().collect(Collectors.groupingBy(p -> p.getProductCode() + "_" + p.getProductBatch() + "_" + p.getSaleManName()));
        int a = 0;
        for (String s : collect.keySet()) {


            //部门
            String BM = "";
            String BMC = "";
            //商品
            SPBH = s.split("_")[0];
            //进货价
            BigDecimal JE = new BigDecimal("0");
            //售卖价
            BigDecimal JEv = new BigDecimal("0");
            BigDecimal DJ = new BigDecimal("0");
            BigDecimal DJv = new BigDecimal("0");
            BigDecimal WB = new BigDecimal("0");
            BigDecimal WBv = new BigDecimal("0");
            int SL = 0;
            List<BusErpOrderDetails> busErpOrderDetails1 = collect.get(s);
            BusErpOrderDetails busErpOrderDetails = busErpOrderDetails1.get(0);
            for (BusErpOrderDetails erpOrderDetails : busErpOrderDetails1) {
                //同批次卖出商品
                List<EntityMap> saleProductList = hyRemoteOrderService.getSaleProductByBatch(dbName, erpOrderDetails.getProductCode(), erpOrderDetails.getProductBatch(), erpOrderDetails.getOrderDate());
                int saleNum = saleProductList.stream().map(e -> e.get("num")).mapToInt(c -> (int) c).sum();

                //商品进货价格
                List<EntityMap> buyProductList = hyRemoteOrderService.getBuyProductByBatch(dbName, erpOrderDetails.getProductCode(), erpOrderDetails.getProductBatch());
                if (CollUtil.isEmpty(buyProductList)) {
                    throw new RuntimeException(erpOrderDetails.getProductName() + "【" + erpOrderDetails.getProductCode() + "】" + erpOrderDetails.getProductBatch() + "未匹配到进货单");
                }
                if (buyProductList.size() > 1) {
                    int num_ = 0;
                    for (EntityMap entityMap : buyProductList) {
                        Integer num = entityMap.getInt("num");
                        num_ = num_ + num;
                        if (saleNum <= num_) {
                            DJ = entityMap.get("productPrice");
                            break;
                        }
                    }

                } else {
                    DJ = buyProductList.get(0).get("productPrice");
                }
                BigDecimal rate = new BigDecimal(1.13).setScale(2, RoundingMode.HALF_UP);
                if (CollUtil.isNotEmpty(productCodes) && productCodes.contains(erpOrderDetails.getProductCode())) {
                    //    生物制品的药
                    rate = new BigDecimal(1.03).setScale(2, RoundingMode.HALF_UP);
                }
                DJ = DJ.divide(rate, 2, BigDecimal.ROUND_HALF_UP);
                DJv = erpOrderDetails.getProductPrice().divide(rate, 2, BigDecimal.ROUND_HALF_UP);

                SL = SL + erpOrderDetails.getProductNum();
                JE = JE.add(DJ.multiply(new BigDecimal(erpOrderDetails.getProductNum())).setScale(2, RoundingMode.HALF_UP));

                JEv = JEv.add(DJv.multiply(new BigDecimal(erpOrderDetails.getProductNum())).setScale(2, RoundingMode.HALF_UP));
            }

            ZY = busErpOrderDetails.getCompanyName().replaceAll("\\.", "");
            //BM = busErpOrderDetails.getSaleManName().indexOf("Z")==0 ?busErpOrderDetails.getSaleManName() :busErpOrderDetails.getDeptName();
            //BM = (Character.isLowerCase(busErpOrderDetails.getSaleManName().charAt(0)) || Character.isUpperCase(busErpOrderDetails.getSaleManName().charAt(0))) ? (busErpOrderDetails.getSaleManName().indexOf("Z") == 0 ? busErpOrderDetails.getSaleManName() : busErpOrderDetails.getDeptName()) : "销售部";
            BM = (Character.isLowerCase(busErpOrderDetails.getSaleManName().charAt(0)) || Character.isUpperCase(busErpOrderDetails.getSaleManName().charAt(0))) ? busErpOrderDetails.getSaleManName() : busErpOrderDetails.getDeptName();
            BM = BM.indexOf("商务") != -1 ? "Z" + getNumeric(BM) : BM;

            LcZWFZYS lcZWFZYS = new LcZWFZYS();
            lcZWFZYS.setZWFZYS_DWBH(DWBH);
            //lcZWFZYS.setZWFZYS_PZNM(PZNM);
            //lcZWFZYS.setZWFZYS_FLNM(IdWorker.get32UUID());

            lcZWFZYS.setZWFZYS_YSBH(String.format("%04d", (a + 1)));
            lcZWFZYS.setZWFZYS_KMBH("");
            // ERP 部门名称
            String bmbh = lcRemoteOrderService.getBMBH(BM, DWBH);
            bmbh = bmbh == null ? lcRemoteOrderService.getBMBH(busErpOrderDetails.getDeptCode(), DWBH) : bmbh;

            lcZWFZYS.setZWFZYS_BMBH(bmbh == null ? "" : bmbh);
            lcZWFZYS.setZWFZYS_ZGBH("");
            lcZWFZYS.setZWFZYS_CPBH("");
            //ERP 商品
            String spbh = lcRemoteOrderService.getSPBH(SPBH, DWBH);
            lcZWFZYS.setZWFZYS_XMBH(spbh == null ? "" : "000000-" + spbh);


            lcZWFZYS.setZWFZYS_WBBH("01");
            lcZWFZYS.setZWFZYS_JZFX("2");
            BigDecimal price=new BigDecimal("0");
            if(SL>0){
                price=JE.divide(new BigDecimal(SL),2, BigDecimal.ROUND_HALF_UP);
            }
            lcZWFZYS.setZWFZYS_SL(SL);
            lcZWFZYS.setZWFZYS_DJ(price);
            lcZWFZYS.setZWFZYS_DJv(DJv);
            lcZWFZYS.setZWFZYS_WB(WB);
            lcZWFZYS.setZWFZYS_HL("");
            //lcZWFZYS.setZWFZYS_JE(DJ.multiply(new BigDecimal(SL)).setScale(2, RoundingMode.HALF_UP));
            lcZWFZYS.setZWFZYS_JE(JE);
            lcZWFZYS.setZWFZYS_JEv(JEv);
            lcZWFZYS.setZWFZYS_YWRQ(PZRQ);
            lcZWFZYS.setZWFZYS_DWDZ(0);
            lcZWFZYS.setZWFZYS_SJ01(0);
            lcZWFZYS.setZWFZYS_SJ02(0);
            lcZWFZYS.setZWFZYS_SJ03(0);
            lcZWFZYS.setZWFZYS_SJ04(0);
            lcZWFZYS.setZWFZYS_SJ05(0);
            lcZWFZYS.setZWFZYS_YT(ZY);
            lcZWFZYS.setZWFZYS_YHDZ(0);
            lcZWFZYS.setZWFZYS_JSRQ(PZRQ);
            lcZWFZYS.setZWFZYS_ZPDY("0");
            lcZWFZYS.setCreator("");
            //lcZWFZYS.setCreatedTime(DateUtil.now());
            lcZWFZYS.setLastModifier("");
            //lcZWFZYS.setLastModifiedTime(DateUtil.now());
            //lcZWFZYS.setZWFZYS_ID(IdWorker.get32UUID());
            lcZWFZYS.setZWFZYS_BMVersion("1");
            lcZWFZYS.setZWFZYS_WLDWVersion("1");
            lcZWFZYS.setZWFZYS_ZJDJBZ("");
            lcZWFZYS.setZWFZYS_KJLX("0");
            LcZWFZYSS.add(lcZWFZYS);
        }


        // 主记录
        LcZWPZK lcZWPZK = new LcZWPZK();
        lcZWPZK.setZWPZK_DWBH(DWBH);
        //lcZWPZK.setZWPZK_PZNM(PZNM);
        lcZWPZK.setZWPZK_KJND(KJND);
        lcZWPZK.setZWPZK_KJQJ(KJQJ);
        lcZWPZK.setZWPZK_PZRQ(PZRQ);
        lcZWPZK.setZWPZK_PZBH(PZBHStr);
        lcZWPZK.setZWPZK_LXBH("01");
        lcZWPZK.setZWPZK_FJZS(0);
        lcZWPZK.setZWPZK_TYPE(0);
        lcZWPZK.setZWPZK_ZDR(user.getNickName());
        lcZWPZK.setSysUserID(user.getAvatar());
        lcZWPZK.setZWPZK_FHF(0);
        lcZWPZK.setZWPZK_JZF(0);
        lcZWPZK.setZWPZK_WZF(1);
        lcZWPZK.setZWPZK_ZFF(0);
        lcZWPZK.setZWPZK_XJDQ(0);
        lcZWPZK.setZWPZK_PZZT(1);
        lcZWPZK.setZWPZK_ZDBZ(0);
        lcZWPZK.setZWPZK_TZDZS(0);
        //lcZWPZK.setZWPZK_ID(IdWorker.get32UUID());
        String str=orderNo.length() <80?orderNo:orderNos.size()+"";
        lcZWPZK.setZWPZK_ZY(DateUtil.now() + "结转成本" + (str));
        BigDecimal je = new BigDecimal(0);
        BigDecimal jev = new BigDecimal(0);
        for (LcZWFZYS zwfzys : LcZWFZYSS) {
            je = je.add(zwfzys.getZWFZYS_JE());
            jev = jev.add(zwfzys.getZWFZYS_JEv());
        }
        lcZWPZK.setZWPZK_JE(je);
        lcZWPZK.setCreator("");
        //lcZWPZK.setCreatedTime(DateUtil.now());
        lcZWPZK.setLastModifier("");
        //lcZWPZK.setLastModifiedTime(DateUtil.now());
        lcZWPZK.setZWPZK_DWVersion("1");
        lcZWPZK.setSecretLevelNum("0");
        lcZWPZK.setImageBarCode("");
        lcZWPZK.setImageElecVoucher("");
        lcZWPZK.setZWPZK_DYF("");
        //lcZWPZK.setZWPZK_PZKID(IdWorker.get32UUID());
        lcZWPZK.setZWPZK_ZDRBH(user.getUsername());
        //lcRemoteOrderService.insertZWPZK(lcZWPZK);

        //凭证明细
        List<LcZWPZFL> lcZWPZFLS = new ArrayList<>();
        //640101	主营业务成本-销售商品成本
        String KMBH11 = "640101", KMBH13 = "140501";
        if (companyId.equals(1017L)) {
            KMBH11 = "640102";
            KMBH13 = "140502";
        }

        LcZWPZFL lcZWPZFL = new LcZWPZFL();
        lcZWPZFL.setZWPZFL_DWBH(DWBH);
        //lcZWPZFL.setZWPZFL_PZNM(PZNM);
        //lcZWPZFL.setZWPZFL_FLNM(IdWorker.get32UUID());
        lcZWPZFL.setZWPZFL_FLBH("0001");
        lcZWPZFL.setZWPZFL_KMBH(KMBH11);
        lcZWPZFL.setZWPZFL_JSFS("");
        String str1=orderNo.length() <80?orderNo:orderNos.size()+"";
        lcZWPZFL.setZWPZFL_ZY("结转成本" + (str1));

        lcZWPZFL.setZWPZFL_JE(je);
        lcZWPZFL.setZWPZFL_SL(0);
        lcZWPZFL.setZWPZFL_DJ(new BigDecimal(0));
        lcZWPZFL.setZWPZFL_WB(new BigDecimal(0));
        lcZWPZFL.setZWPZFL_HL(1);
        lcZWPZFL.setZWPZFL_JZFX(1);
        lcZWPZFL.setZWPZFL_JFJE(je);
        lcZWPZFL.setZWPZFL_DFJE(new BigDecimal(0));

        lcZWPZFL.setZWPZFL_WBBH("01");
        lcZWPZFL.setZWPZFL_YHDZ("0");
        //lcZWPZFL.setZWPZFL_ID(IdWorker.get32UUID());
        lcZWPZFL.setCreator("");
        //lcZWPZFL.setCreatedTime(DateUtil.now());
        lcZWPZFL.setLastModifier("");
        //lcZWPZFL.setLastModifiedTime(DateUtil.now());
        lcZWPZFL.setZWPZFL_KJLX("0");
        lcZWPZFL.setZWPZFL_DZZD("");
        //lcZWPZFLS.add(lcZWPZFL);
        //科目辅助项
        List<LcZWFZYS> LcZWFZYSS1 = deepCopy(LcZWFZYSS);
        String finalKMBH = KMBH11;
        LcZWFZYSS1.forEach(s1 -> {
            s1.setZWFZYS_KMBH(finalKMBH);
            s1.setZWFZYS_JZFX("1");
            //s1.setZWFZYS_DJ(s1.getZWFZYS_DJv());
            //成本结转
            //s1.setZWFZYS_JE(s1.getZWFZYS_JEv());
            s1.setZWFZYS_FLNM(lcZWPZFL.getZWPZFL_FLNM());
            //s1.setZWFZYS_ID(IdWorker.get32UUID());
        });

           /*   LcZWPZFL lcZWPZFL2 = new LcZWPZFL();
            lcZWPZFL2.setZWPZFL_DWBH(DWBH);
            lcZWPZFL2.setZWPZFL_PZNM(PZNM);
            lcZWPZFL2.setZWPZFL_FLNM(IdWorker.get32UUID());
            lcZWPZFL2.setZWPZFL_FLBH("0002");
            lcZWPZFL2.setZWPZFL_KMBH(KMBH12);
            lcZWPZFL2.setZWPZFL_JSFS("");


          List<LcZWFZYS> LcZWFZYSS2 = new ArrayList<>();
            Map<String, List<LcZWFZYS>> bms = LcZWFZYSS.stream().filter(i -> i.getZWFZYS_BMBH() != null).collect(Collectors.groupingBy(LcZWFZYS::getZWFZYS_BMBH));
            int it = 0;
            for (String bm : bms.keySet()) {
                List<LcZWFZYS> lcZWFZYS_ = bms.get(bm);
                it++;
                LcZWFZYS lcZWFZYS = new LcZWFZYS();
                lcZWFZYS.setZWFZYS_DWBH(DWBH);
                lcZWFZYS.setZWFZYS_PZNM(PZNM);
                lcZWFZYS.setZWFZYS_FLNM(lcZWPZFL2.getZWPZFL_FLNM());
                lcZWFZYS.setZWFZYS_YSBH(String.format("%04d", (it)));
                lcZWFZYS.setZWFZYS_KMBH(KMBH12);
                // ERP 部门名称
                //String bmbh = lcRemoteOrderService.getBMBH(bm);
                lcZWFZYS.setZWFZYS_BMBH(bm);

                //ERP 单位名称
                //String dwbh = lcRemoteOrderService.getDWBH(ZY);
                //lcZWFZYS.setZWFZYS_WLDWBH(dwbh == null ? "10010404" : dwbh);

                lcZWFZYS.setZWFZYS_ZGBH("");
                lcZWFZYS.setZWFZYS_CPBH("");
                //ERP 商品
                //String spbh = lcRemoteOrderService.getSPBH(SPBH, DWBH);
                //lcZWFZYS.setZWFZYS_XMBH("000000-" + spbh == null ? "000064" : spbh);
                lcZWFZYS.setZWFZYS_WBBH("01");
                lcZWFZYS.setZWFZYS_JZFX("2");
                lcZWFZYS.setZWFZYS_SL(lcZWFZYS_.stream().map(LcZWFZYS::getZWFZYS_SL).mapToInt(i -> i).sum());

                lcZWFZYS.setZWFZYS_DJ(new BigDecimal(0));
                lcZWFZYS.setZWFZYS_WB(new BigDecimal(0));
                //lcZWFZYS.setZWFZYS_DJ(new BigDecimal(lcZWFZYS_.stream().map(LcZWFZYS::getZWFZYS_DJ).mapToDouble(b -> b).sum()));
                //lcZWFZYS.setZWFZYS_WB(new BigDecimal(lcZWFZYS_.stream().map(LcZWFZYS::getZWFZYS_WB).mapToDouble(b -> b).sum()));
                lcZWFZYS.setZWFZYS_HL("");
                BigDecimal je2 = new BigDecimal(0);
                for (LcZWFZYS zwfzys : lcZWFZYS_) {
                    je2 = je2.add(zwfzys.getZWFZYS_JE());
                }
                lcZWFZYS.setZWFZYS_JE(je2.setScale(2, RoundingMode.HALF_UP));
                lcZWFZYS.setZWFZYS_YWRQ(PZRQ);
                lcZWFZYS.setZWFZYS_DWDZ(0);
                lcZWFZYS.setZWFZYS_SJ01(0);
                lcZWFZYS.setZWFZYS_SJ02(0);
                lcZWFZYS.setZWFZYS_SJ03(0);
                lcZWFZYS.setZWFZYS_SJ04(0);
                lcZWFZYS.setZWFZYS_SJ05(0);
                lcZWFZYS.setZWFZYS_YT("");
                lcZWFZYS.setZWFZYS_YHDZ(0);
                lcZWFZYS.setZWFZYS_JSRQ(PZRQ);
                lcZWFZYS.setZWFZYS_ZPDY("0");
                lcZWFZYS.setCreator("");
                lcZWFZYS.setCreatedTime(DateUtil.now());
                lcZWFZYS.setLastModifier("");
                lcZWFZYS.setLastModifiedTime(DateUtil.now());
                lcZWFZYS.setZWFZYS_ID(IdWorker.get32UUID());
                lcZWFZYS.setZWFZYS_BMVersion("1");
                lcZWFZYS.setZWFZYS_WLDWVersion("1");
                lcZWFZYS.setZWFZYS_ZJDJBZ("");
                lcZWFZYS.setZWFZYS_KJLX("0");
                LcZWFZYSS2.add(lcZWFZYS);
            }
            lcZWPZFL2.setZWPZFL_ZY("结转成本");
            BigDecimal JE2 = new BigDecimal(0);
            for (LcZWFZYS lcZWFZYS : LcZWFZYSS2) {
                JE2 = JE2.add(lcZWFZYS.getZWFZYS_JE());
            }
            lcZWPZFL2.setZWPZFL_JE(JE2.setScale(2, RoundingMode.HALF_UP));
            lcZWPZFL2.setZWPZFL_SL(0);
            lcZWPZFL2.setZWPZFL_DJ(new BigDecimal(0));
            lcZWPZFL2.setZWPZFL_WB(new BigDecimal(0));
            lcZWPZFL2.setZWPZFL_HL(1);
            lcZWPZFL2.setZWPZFL_JZFX(2);
            lcZWPZFL2.setZWPZFL_WBBH("01");
            lcZWPZFL2.setZWPZFL_YHDZ("0");
            lcZWPZFL2.setZWPZFL_ID(IdWorker.get32UUID());
            lcZWPZFL2.setCreator("");
            lcZWPZFL2.setCreatedTime(DateUtil.now());
            lcZWPZFL2.setLastModifier("");
            lcZWPZFL2.setLastModifiedTime(DateUtil.now());
            lcZWPZFL2.setZWPZFL_KJLX("0");
            lcZWPZFL2.setZWPZFL_DZZD("");
            lcZWPZFLS.add(lcZWPZFL2);*/

        //140501	库存商品-商品
        LcZWPZFL lcZWPZFL3 = new LcZWPZFL();
        lcZWPZFL3.setZWPZFL_DWBH(DWBH);
        //lcZWPZFL3.setZWPZFL_PZNM(PZNM);
        //lcZWPZFL3.setZWPZFL_FLNM(IdWorker.get32UUID());
        lcZWPZFL3.setZWPZFL_FLBH("0003");
        lcZWPZFL3.setZWPZFL_KMBH(KMBH13);
        lcZWPZFL3.setZWPZFL_JSFS("");
        String str2=orderNo.length() <80?orderNo:orderNos.size()+"";
        lcZWPZFL3.setZWPZFL_ZY("结转成本" + (str2));
        lcZWPZFL3.setZWPZFL_SL(0);
        lcZWPZFL3.setZWPZFL_DJ(new BigDecimal(0));
        lcZWPZFL3.setZWPZFL_WB(new BigDecimal(0));
        lcZWPZFL3.setZWPZFL_HL(1);
        lcZWPZFL3.setZWPZFL_WBBH("01");
        lcZWPZFL3.setZWPZFL_YHDZ("0");
        //lcZWPZFL3.setZWPZFL_ID(IdWorker.get32UUID());
        lcZWPZFL3.setCreator("");
        //lcZWPZFL3.setCreatedTime(DateUtil.now());
        lcZWPZFL3.setLastModifier("");
        //lcZWPZFL3.setLastModifiedTime(DateUtil.now());
        lcZWPZFL3.setZWPZFL_KJLX("0");
        lcZWPZFL3.setZWPZFL_DZZD("");

        //List<LcZWFZYS> LcZWFZYSS3 = LcZWFZYSS.stream().collect(Collectors.toList());
        List<LcZWFZYS> LcZWFZYSS3 = deepCopy(LcZWFZYSS);
        BigDecimal JE3 = new BigDecimal(0);

        for (LcZWFZYS s3 : LcZWFZYSS3) {
            s3.setZWFZYS_KMBH(KMBH13);
            s3.setZWFZYS_JZFX("2");
            s3.setZWFZYS_FLNM(lcZWPZFL3.getZWPZFL_FLNM());
            //s3.setZWFZYS_ID(IdWorker.get32UUID());
            JE3 = JE3.add(s3.getZWFZYS_JE());
        }
        lcZWPZFL3.setZWPZFL_JZFX(2);
        lcZWPZFL3.setZWPZFL_DFJE(JE3);
        lcZWPZFL3.setZWPZFL_JFJE(new BigDecimal(0));

        lcZWPZFL3.setZWPZFL_JE(JE3);
        //lcZWPZFLS.add(lcZWPZFL3);

        //lcRemoteOrderService.insertZWPZFL(lcZWPZFLS);
        //
        //lcRemoteOrderService.insertZWFZYS(LcZWFZYSS3);
        ////lcRemoteOrderService.insertZWFZYS(LcZWFZYSS2);
        //lcRemoteOrderService.insertZWFZYS(LcZWFZYSS1);

        lcZWPZFL3.setVoucherfzhs(LcZWFZYSS3);
        lcZWPZFL.setVoucherfzhs(LcZWFZYSS1);
        lcZWPZFLS.add(lcZWPZFL3);
        lcZWPZFLS.add(lcZWPZFL);
        lcZWPZK.setVoucherfl(lcZWPZFLS);

        JSONObject obj = JSONUtil.createObj();
        obj.set("voucherHead", lcZWPZK);

        String s = JSONUtil.toJsonStr(obj);
        System.out.println("#########################凭证参数:"+s);
        log.info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@凭证参数",s);
        if(isOnline) {
            String result = HttpUtil.post(lcApi, s);
            JSONObject jsonObject = JSONUtil.parseObj(result);
            if ("200".equals(jsonObject.getStr("code"))) {

                //jsonObject.get("data")
                String data = jsonObject.get("data").toString();

                JSONObject objData = JSONUtil.parseObj(data);
                Object savedVochers = objData.get("SavedVochers");
                int state = 0;
                String voucher = "";

                if (objData.get("FailedVochers").toString().length() > 3) {
                    savedVochers = objData.get("FailedVochers");
                    voucher = savedVochers.toString();
                    state = 3;

                } else {
                    savedVochers = savedVochers.toString().substring(savedVochers.toString().indexOf("#") + 1, savedVochers.toString().indexOf("#") + 6);
                    state = 1;
                    voucher = currentDay + " " + savedVochers;
                }

                hyRemoteOrderService.updateCbVocher(dbName, state, voucher, StrUtil.split(orderNo, ','));
            } else {
                hyRemoteOrderService.updateCbVocher(dbName, 3, "", StrUtil.split(orderNo, ','));
            }
           /* busErpOrderService.update(new UpdateWrapper<BusErpOrder>().lambda().set(BusErpOrder::getVoucherJSON, s + result).set(BusErpOrder::getUpdateTime, DateUtil.date()).set(BusErpOrder::getVoucherHandleState, state).set(BusErpOrder::getVoucher, voucher).eq(BusErpOrder::getOrderType, VoucherTypeEnum.Cb.getCode()).in(BusErpOrder::getOrderNo, busErpOrderDetailsList.stream().map(BusErpOrderDetails::getOrderNo).collect(Collectors.toList())));
            List<BusErpOrder> list = busErpOrderService.list(new QueryWrapper<BusErpOrder>().lambda().eq(BusErpOrder::getOrderType, orderType).in(BusErpOrder::getOrderNo, StrUtil.split(orderNo, ',')));
            for (BusErpOrder busErpOrder : list) {
                busErpOrder.setVoucherCount(busErpOrder.getVoucherCount() + 1);
            }
            busErpOrderService.saveOrUpdateBatch(list);
        } else {
            busErpOrderService.update(new UpdateWrapper<BusErpOrder>().lambda().set(BusErpOrder::getVoucherJSON, s + result).set(BusErpOrder::getUpdateTime, DateUtil.date()).set(BusErpOrder::getVoucherHandleState, 3).set(BusErpOrder::getVoucher, jsonObject.getStr("msg")).eq(BusErpOrder::getOrderType, VoucherTypeEnum.Cb.getCode()).in(BusErpOrder::getOrderNo, busErpOrderDetailsList.stream().map(BusErpOrderDetails::getOrderNo).collect(Collectors.toList())));
            List<BusErpOrder> list = busErpOrderService.list(new QueryWrapper<BusErpOrder>().lambda().eq(BusErpOrder::getOrderType, orderType).in(BusErpOrder::getOrderNo, StrUtil.split(orderNo, ',')));
            for (BusErpOrder busErpOrder : list) {
                busErpOrder.setVoucherCount(busErpOrder.getVoucherCount() + 1);
            }
            busErpOrderService.saveOrUpdateBatch(list);
        }*/
        }
    }

    //收付款
    void sfk(Long companyId,List<BusErpOrderDetails> busErpOrderDetailsList, String currentDay1, String orderNo,List<String> orderNos, OpenUser user, String orderType, String dbName, String ZY, String SPBH, String DWBH, String KJND, String KJQJ, String PZRQ, String PZNM, String PZBHStr, List<String> productCodes) {
      /*  String DWBH ="", KJND = "", KJQJ = "",orderNo="";
        //String DWBH = busCwErp.getCompanyCode(), KJND = currentDay.split("-")[0], KJQJ = currentDay.split("-")[1];
        //String PZRQ = currentDay.replaceAll("-", "");
        String PZRQ = "";
        //制证人
        EntityMap defUserId = busErpOrderService.getDefUserId(DWBH);

        // 凭证号
        int PZBH = 1;
        EntityMap zwpzbh = lcRemoteOrderService.getZWPZBH(DWBH, KJND, KJQJ);
        String PZNM = lcRemoteOrderService.getMaxPZNM() + 1 + "";
        if (CollUtil.isEmpty(zwpzbh)) {
            LcZWPZBH lcZWPZBH = new LcZWPZBH();
            lcZWPZBH.setZWPZBH_DWBH(DWBH);
            lcZWPZBH.setZWPZBH_KJND(KJND);
            lcZWPZBH.setZWPZBH_KJQJ(KJQJ);
            lcZWPZBH.setZWPZBH_PZZ("0");
            lcZWPZBH.setZWPZBH_PZRQ(PZRQ);
            lcZWPZBH.setCreator("");
            lcZWPZBH.setCreatedTime(DateUtil.now());
            lcZWPZBH.setZWPZBH_ID(IdWorker.get32UUID());
            lcZWPZBH.setZWPZBH_PZBH(PZBH);
            List<LcZWPZBH> lcZWPZBHList = new ArrayList<>();
            lcZWPZBHList.add(lcZWPZBH);
            lcRemoteOrderService.insertZWPZBH(lcZWPZBHList);
        } else {
            Integer zwpzbh_pzbh = zwpzbh.getInt("ZWPZBH_PZBH");
            PZBH = zwpzbh_pzbh + 1;
            lcRemoteOrderService.changeZWPZBH(DWBH, KJND, KJQJ, PZBH, PZRQ);
        }

        String PZBHStr = String.format("%05d", PZBH);*/
        List<LcZWFZYS> LcZWFZYSS = new ArrayList<>();
        String currentDay = DatePattern.NORM_DATE_FORMAT.format(busErpOrderDetailsList.get(0).getCreateTime());
        // 记录商品
        Map<String, List<BusErpOrderDetails>> collect = busErpOrderDetailsList.stream().collect(Collectors.groupingBy(p -> p.getProductCode() + "_" + p.getProductBatch()));
        int a = 0;
        //单位
        ZY = "";
        BigDecimal ZJE = new BigDecimal("0");

        for (String s : collect.keySet()) {
            //部门
            String BM = "";
            //商品
            SPBH = s.split("_")[0];
            BigDecimal JE = new BigDecimal("0");
            BigDecimal JEv = new BigDecimal("0");
            BigDecimal DJ = new BigDecimal("0");
            BigDecimal DJv = new BigDecimal("0");
            BigDecimal WB = new BigDecimal("0");
            BigDecimal WBv = new BigDecimal("0");
            int SL = 0;
            List<BusErpOrderDetails> busErpOrderDetails1 = collect.get(s);
            BusErpOrderDetails busErpOrderDetails = busErpOrderDetails1.get(0);

            for (BusErpOrderDetails erpOrderDetails : busErpOrderDetails1) {
                DJ = erpOrderDetails.getProductPrice();
                JE = JE.add(erpOrderDetails.getProductSaleAmount());
                ZJE = ZJE.add(erpOrderDetails.getProductSaleAmount());
                SL = SL + erpOrderDetails.getProductNum();
            }

            ZY = busErpOrderDetails.getCompanyName().replaceAll("\\.", "");
            //BM = busErpOrderDetails.getSaleManName().indexOf("Z")==0 ?busErpOrderDetails.getSaleManName() :busErpOrderDetails.getDeptName();
            //BM = (Character.isLowerCase(busErpOrderDetails.getSaleManName().charAt(0)) || Character.isUpperCase(busErpOrderDetails.getSaleManName().charAt(0))) ? (busErpOrderDetails.getSaleManName().indexOf("Z") == 0 ? busErpOrderDetails.getSaleManName() : busErpOrderDetails.getDeptName()) : "销售部";
            BM = (Character.isLowerCase(busErpOrderDetails.getSaleManName().charAt(0)) || Character.isUpperCase(busErpOrderDetails.getSaleManName().charAt(0))) ? busErpOrderDetails.getSaleManName() : busErpOrderDetails.getDeptName();
            BM = BM.indexOf("商务") != -1 ? "Z" + getNumeric(BM) : BM;

            LcZWFZYS lcZWFZYS = new LcZWFZYS();
            lcZWFZYS.setZWFZYS_DWBH(DWBH);
            //lcZWFZYS.setZWFZYS_PZNM(PZNM);
            //lcZWFZYS.setZWFZYS_FLNM(IdWorker.get32UUID());
            lcZWFZYS.setZWFZYS_YSBH(String.format("%04d", (a + 1)));
            lcZWFZYS.setZWFZYS_KMBH("");

            //ERP 单位名称
            String dwbh = lcRemoteOrderService.getDWBH2(ZY, DWBH);
            dwbh = dwbh == null ? lcRemoteOrderService.getDWBH(ZY, DWBH) : dwbh;

            lcZWFZYS.setZWFZYS_WLDWBH(dwbh == null ? "" : dwbh);
            // ERP 部门名称
            String bmbh = lcRemoteOrderService.getBMBH(BM, DWBH);
            bmbh = bmbh == null ? lcRemoteOrderService.getBMBH(busErpOrderDetails.getDeptCode(), DWBH) : bmbh;

            lcZWFZYS.setZWFZYS_BMBH(bmbh == null ? "" : bmbh);
            lcZWFZYS.setZWFZYS_ZGBH("");
            lcZWFZYS.setZWFZYS_CPBH("");
            //ERP 商品
            String spbh = lcRemoteOrderService.getSPBH(SPBH, DWBH);
            lcZWFZYS.setZWFZYS_XMBH(spbh == null ? "" : "000000-" + spbh);
            lcZWFZYS.setZWFZYS_WBBH("01");
            lcZWFZYS.setZWFZYS_JZFX("2");
            lcZWFZYS.setZWFZYS_SL(SL);
            lcZWFZYS.setZWFZYS_DJ(DJ);
            lcZWFZYS.setZWFZYS_DJv(DJv);
            lcZWFZYS.setZWFZYS_WB(WB);
            lcZWFZYS.setZWFZYS_HL("");
            lcZWFZYS.setZWFZYS_JE(JE);
            //lcZWFZYS.setZWFZYS_JE(DJ.multiply(new BigDecimal(SL)).setScale(2, RoundingMode.HALF_UP));
            lcZWFZYS.setZWFZYS_JEv(JEv);
            lcZWFZYS.setZWFZYS_YWRQ(PZRQ);
            lcZWFZYS.setZWFZYS_DWDZ(0);
            lcZWFZYS.setZWFZYS_SJ01(0);
            lcZWFZYS.setZWFZYS_SJ02(0);
            lcZWFZYS.setZWFZYS_SJ03(0);
            lcZWFZYS.setZWFZYS_SJ04(0);
            lcZWFZYS.setZWFZYS_SJ05(0);
            lcZWFZYS.setZWFZYS_YT(busErpOrderDetails.getOrderNo());
            lcZWFZYS.setZWFZYS_YHDZ(0);
            lcZWFZYS.setZWFZYS_JSRQ(PZRQ);
            lcZWFZYS.setZWFZYS_ZPDY("0");
            lcZWFZYS.setCreator("");
            //lcZWFZYS.setCreatedTime(DateUtil.now());
            lcZWFZYS.setLastModifier("");
            //lcZWFZYS.setLastModifiedTime(DateUtil.now());
            //lcZWFZYS.setZWFZYS_ID(IdWorker.get32UUID());
            lcZWFZYS.setZWFZYS_BMVersion("1");
            lcZWFZYS.setZWFZYS_WLDWVersion("1");
            lcZWFZYS.setZWFZYS_ZJDJBZ("");
            lcZWFZYS.setZWFZYS_KJLX("0");
            LcZWFZYSS.add(lcZWFZYS);
        }


        // 主记录
        LcZWPZK lcZWPZK = new LcZWPZK();
        lcZWPZK.setZWPZK_DWBH(DWBH);
        //lcZWPZK.setZWPZK_PZNM(PZNM);
        lcZWPZK.setZWPZK_KJND(KJND);
        lcZWPZK.setZWPZK_KJQJ(KJQJ);
        lcZWPZK.setZWPZK_PZRQ(PZRQ);
        lcZWPZK.setZWPZK_PZBH(PZBHStr);
        lcZWPZK.setZWPZK_LXBH("01");
        lcZWPZK.setZWPZK_FJZS(0);
        lcZWPZK.setZWPZK_TYPE(0);
        lcZWPZK.setZWPZK_ZDR(user.getNickName());
        lcZWPZK.setSysUserID(user.getAvatar());
        lcZWPZK.setZWPZK_KJZG(" ");
        lcZWPZK.setZWPZK_FHF(0);
        lcZWPZK.setZWPZK_JZF(0);
        lcZWPZK.setZWPZK_WZF(1);
        lcZWPZK.setZWPZK_ZFF(0);
        lcZWPZK.setZWPZK_XJDQ(0);
        lcZWPZK.setZWPZK_PZZT(1);
        lcZWPZK.setZWPZK_ZDBZ(0);
        lcZWPZK.setZWPZK_TZDZS(0);
        //lcZWPZK.setZWPZK_ID(IdWorker.get32UUID());
        lcZWPZK.setZWPZK_ZY(currentDay + ZY + "");
        //lcZWPZK.setZWPZK_ZY(DatePattern.NORM_DATE_FORMAT.format(DateUtil.date()) + ZY+"付款");
        //BigDecimal je = new BigDecimal(0);
        //for (LcZWFZYS zwfzys : LcZWFZYSS) {
        //    je = je.add(zwfzys.getZWFZYS_JE());
        //}
        //lcZWPZK.setZWPZK_JE(je);
        lcZWPZK.setZWPZK_JE(ZJE);
        lcZWPZK.setCreator("");
        //lcZWPZK.setCreatedTime(DateUtil.now());
        lcZWPZK.setLastModifier("");
        //lcZWPZK.setLastModifiedTime(DateUtil.now());
        lcZWPZK.setZWPZK_DWVersion("1");
        lcZWPZK.setSecretLevelNum("0");
        lcZWPZK.setImageBarCode("");
        lcZWPZK.setImageElecVoucher("");
        lcZWPZK.setZWPZK_DYF("");
        //lcZWPZK.setZWPZK_PZKID(IdWorker.get32UUID());
        lcZWPZK.setZWPZK_ZDRBH(user.getUsername());
        //lcRemoteOrderService.insertZWPZK(lcZWPZK);

        //凭证明细
        List<LcZWPZFL> lcZWPZFLS = new ArrayList<>();
        //220201	应付账款-应付账款
        String KMBH11 = "220201", KMBH13 = "";
        LcZWPZFL lcZWPZFL = new LcZWPZFL();
        LcZWPZFL lcZWPZFL3 = new LcZWPZFL();
        lcZWPZFL.setZWPZFL_FLBH("0001");
        lcZWPZFL3.setZWPZFL_FLBH("0003");

        if (VoucherTypeEnum.Sk.getCode().equals(Integer.valueOf(orderType))) {
            KMBH11 = "112202";
            //KMBH13 = "10020203";
            lcZWPZFL.setZWPZFL_FLBH("0003");
            lcZWPZFL3.setZWPZFL_FLBH("0001");
        }
        lcZWPZFL.setZWPZFL_DWBH(DWBH);
        //lcZWPZFL.setZWPZFL_PZNM(PZNM);
        //lcZWPZFL.setZWPZFL_FLNM(IdWorker.get32UUID());
        lcZWPZFL.setZWPZFL_KMBH(KMBH11);
        lcZWPZFL.setZWPZFL_JSFS("");
        lcZWPZFL.setZWPZFL_ZY(currentDay + ZY + LcZWFZYSS.get(0).getZWFZYS_YT());

        //lcZWPZFL.setZWPZFL_JE(je);
        lcZWPZFL.setZWPZFL_JE(ZJE);
        lcZWPZFL.setZWPZFL_SL(0);
        lcZWPZFL.setZWPZFL_DJ(new BigDecimal(0));
        lcZWPZFL.setZWPZFL_WB(new BigDecimal(0));
        lcZWPZFL.setZWPZFL_HL(1);
        lcZWPZFL.setZWPZFL_JZFX(1);
        lcZWPZFL.setZWPZFL_JFJE(ZJE);
        lcZWPZFL.setZWPZFL_DFJE(new BigDecimal(0));
        String fx = "-1";
        if (VoucherTypeEnum.Sk.getCode().equals(Integer.valueOf(orderType))) {
            lcZWPZFL.setZWPZFL_JZFX(2);
            lcZWPZFL.setZWPZFL_DFJE(ZJE);
            lcZWPZFL.setZWPZFL_JFJE(new BigDecimal(0));
            fx = "1";
        }
        lcZWPZFL.setZWPZFL_WBBH("01");
        lcZWPZFL.setZWPZFL_YHDZ("0");
        //lcZWPZFL.setZWPZFL_ID(IdWorker.get32UUID());
        lcZWPZFL.setCreator("");
        //lcZWPZFL.setCreatedTime(DateUtil.now());
        lcZWPZFL.setLastModifier("");
        //lcZWPZFL.setLastModifiedTime(DateUtil.now());
        lcZWPZFL.setZWPZFL_KJLX("0");
        lcZWPZFL.setZWPZFL_DZZD("");
        lcZWPZFLS.add(lcZWPZFL);
        //科目辅助项
        List<LcZWFZYS> LcZWFZYSS1 = deepCopy(LcZWFZYSS);
        String finalKMBH = KMBH11;
        LcZWFZYSS1.forEach(s1 -> {
            s1.setZWFZYS_KMBH(finalKMBH);
            s1.setZWFZYS_JZFX("1");
            if (VoucherTypeEnum.Sk.getCode().equals(Integer.valueOf(orderType))) {
                s1.setZWFZYS_JZFX("2");
            }
            s1.setZWFZYS_FLNM(lcZWPZFL.getZWPZFL_FLNM());
            //s1.setZWFZYS_ID(IdWorker.get32UUID());
        });


        //10020201	银行存款  -湖北赤壁农村商业银行-天骄支行9117

        List<EntityMap> entityMaps = hyRemoteOrderService.receiptPaymentOrderList(fx, dbName, currentDay, null);

        //付款银行科目
        Map<String, String> kmMap = entityMaps.stream().collect(Collectors.toMap(o -> o.get("orderNo").toString(), (o -> o.get("kmCode").toString()), (oldData, newData) -> oldData));
        if (ObjectUtil.isNull(kmMap.get(orderNo))) {
            throw new RuntimeException(orderNo + "未查到科目");
        }
        lcZWPZFL3.setZWPZFL_DWBH(DWBH);
        //lcZWPZFL3.setZWPZFL_PZNM(PZNM);
        //lcZWPZFL3.setZWPZFL_FLNM(IdWorker.get32UUID());
        lcZWPZFL3.setZWPZFL_KMBH(kmMap.get(orderNo));
        KMBH13 = lcZWPZFL3.getZWPZFL_KMBH();
        lcZWPZFL3.setZWPZFL_JSFS("");
        lcZWPZFL3.setZWPZFL_ZY(currentDay + ZY + LcZWFZYSS.get(0).getZWFZYS_YT());
        lcZWPZFL3.setZWPZFL_SL(0);
        lcZWPZFL3.setZWPZFL_DJ(new BigDecimal(0));
        lcZWPZFL3.setZWPZFL_WB(new BigDecimal(0));
        lcZWPZFL3.setZWPZFL_HL(1);
        lcZWPZFL3.setZWPZFL_JZFX(2);
        lcZWPZFL3.setZWPZFL_DFJE(ZJE);
        lcZWPZFL3.setZWPZFL_JFJE(new BigDecimal(0));

        if (VoucherTypeEnum.Sk.getCode().equals(Integer.valueOf(orderType))) {
            lcZWPZFL3.setZWPZFL_JZFX(1);
            lcZWPZFL3.setZWPZFL_JFJE(ZJE);
            lcZWPZFL3.setZWPZFL_DFJE(new BigDecimal(0));
        }
        lcZWPZFL3.setZWPZFL_WBBH("01");
        lcZWPZFL3.setZWPZFL_YHDZ("0");
        //lcZWPZFL3.setZWPZFL_ID(IdWorker.get32UUID());
        lcZWPZFL3.setCreator("");
        //lcZWPZFL3.setCreatedTime(DateUtil.now());
        lcZWPZFL3.setLastModifier("");
        //lcZWPZFL3.setLastModifiedTime(DateUtil.now());
        lcZWPZFL3.setZWPZFL_KJLX("0");
        lcZWPZFL3.setZWPZFL_DZZD("");

        //List<LcZWFZYS> LcZWFZYSS3 = LcZWFZYSS.stream().collect(Collectors.toList());
        List<LcZWFZYS> LcZWFZYSS3 = deepCopy(LcZWFZYSS);
        //BigDecimal JE3 = new BigDecimal(0);
        //for (LcZWFZYS s3 : LcZWFZYSS3) {
        //    JE3 = JE3.add(s3.getZWFZYS_JE());
        //}
        LcZWFZYS lcZWFZYS = LcZWFZYSS3.get(0);
        lcZWFZYS.setZWFZYS_KMBH(KMBH13);
        lcZWFZYS.setZWFZYS_JZFX("2");
        if (VoucherTypeEnum.Sk.getCode().equals(Integer.valueOf(orderType))) {
            lcZWFZYS.setZWFZYS_JZFX("1");
        }
        String str2=orderNo.length() <80?orderNo:orderNos.size()+"";
        lcZWFZYS.setZWFZYS_YT(currentDay + ZY + (str2));
        lcZWFZYS.setZWFZYS_FLNM(lcZWPZFL3.getZWPZFL_FLNM());
        //lcZWFZYS.setZWFZYS_ID(IdWorker.get32UUID());
        if (VoucherTypeEnum.Sk.getCode().equals(Integer.valueOf(orderType))) {
            lcZWFZYS.setZWFZYS_XMBH("000002");
        } else {
            lcZWFZYS.setZWFZYS_XMBH("000005");
        }
        lcZWFZYS.setZWFZYS_JE(ZJE);
        List<LcZWFZYS> LcZWFZYSS33 = new ArrayList<>();
        LcZWFZYSS33.add(lcZWFZYS);

        //lcZWPZFL3.setZWPZFL_JE(JE3);
        lcZWPZFL3.setZWPZFL_JE(ZJE);
        lcZWPZFLS.add(lcZWPZFL3);

        //lcRemoteOrderService.insertZWPZFL(lcZWPZFLS);
        //
        //lcRemoteOrderService.insertZWFZYS(LcZWFZYSS33);
        ////lcRemoteOrderService.insertZWFZYS(LcZWFZYSS2);
        //lcRemoteOrderService.insertZWFZYS(LcZWFZYSS1);

        lcZWPZFL3.setVoucherfzhs(LcZWFZYSS3);
        lcZWPZFL.setVoucherfzhs(LcZWFZYSS1);
        //lcZWPZFLS.add(lcZWPZFL3);
        //lcZWPZFLS.add(lcZWPZFL);
        lcZWPZK.setVoucherfl(lcZWPZFLS);

        JSONObject obj = JSONUtil.createObj();
        obj.set("voucherHead", lcZWPZK);

        String s = JSONUtil.toJsonStr(obj);
        System.out.println("#########################凭证参数:"+s);
        log.info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@凭证参数",s);
        if(isOnline) {
            String result = HttpUtil.post(lcApi, s);
            JSONObject jsonObject = JSONUtil.parseObj(result);

            if ("200".equals(jsonObject.getStr("code"))) {
                String data = jsonObject.get("data").toString();
                JSONObject objData = JSONUtil.parseObj(data);
                Object savedVochers = objData.get("SavedVochers");
                int state = 0;
                String voucher = "";

                if (objData.get("FailedVochers").toString().length() > 3) {
                    savedVochers = objData.get("FailedVochers");
                    voucher = savedVochers.toString();
                    state = 3;
                } else {
                    savedVochers = savedVochers.toString().substring(savedVochers.toString().indexOf("#") + 1, savedVochers.toString().indexOf("#") + 6);
                    state = 1;
                    voucher = currentDay1 + " " + savedVochers;
                }
            /*hyRemoteOrderService.updateCbVocher(dbName, state, voucher, StrUtil.split(orderNo, ','));
        } else {
            hyRemoteOrderService.updateCbVocher(dbName, 3, "", StrUtil.split(orderNo, ','));
        }*/
                busErpOrderService.update(new UpdateWrapper<BusErpOrder>().lambda().set(BusErpOrder::getVoucherJSON, s + result).set(BusErpOrder::getUpdateTime, DateUtil.date()).set(BusErpOrder::getVoucherHandleState, state).set(BusErpOrder::getVoucher, voucher).eq(BusErpOrder::getOrderType, orderType).in(BusErpOrder::getOrderNo, StrUtil.split(orderNo, ',')));
                List<BusErpOrder> list = busErpOrderService.list(new QueryWrapper<BusErpOrder>().lambda().eq(BusErpOrder::getOrderType, orderType).in(BusErpOrder::getOrderNo, StrUtil.split(orderNo, ',')));
                for (BusErpOrder busErpOrder : list) {
                    busErpOrder.setVoucherCount(busErpOrder.getVoucherCount() + 1);
                }
                busErpOrderService.saveOrUpdateBatch(list);
            } else {
                busErpOrderService.update(new UpdateWrapper<BusErpOrder>().lambda().set(BusErpOrder::getVoucherJSON, s + result).set(BusErpOrder::getUpdateTime, DateUtil.date()).set(BusErpOrder::getVoucherHandleState, 3).set(BusErpOrder::getVoucher, jsonObject.getStr("msg")).eq(BusErpOrder::getOrderType, orderType).in(BusErpOrder::getOrderNo, StrUtil.split(orderNo, ',')));
                List<BusErpOrder> list = busErpOrderService.list(new QueryWrapper<BusErpOrder>().lambda().eq(BusErpOrder::getOrderType, orderType).in(BusErpOrder::getOrderNo, StrUtil.split(orderNo, ',')));
                for (BusErpOrder busErpOrder : list) {
                    busErpOrder.setVoucherCount(busErpOrder.getVoucherCount() + 1);
                }
                busErpOrderService.saveOrUpdateBatch(list);
            }
        }

    }

    //样品
    void yp(Long companyId,List<BusErpOrderDetails> busErpOrderDetailsList, String currentDay, String orderNo,List<String> orderNos, OpenUser user, String orderType, String dbName, String ZY, String SPBH, String DWBH, String KJND, String KJQJ, String PZRQ, String PZNM, String PZBHStr, List<String> productCodes) {
        List<LcZWFZYS> LcZWFZYSSv = new ArrayList<>();
        List<LcZWFZYS> LcZWFZYSS = new ArrayList<>();
        // 记录商品
        Map<String, List<BusErpOrderDetails>> collect1 = busErpOrderDetailsList.stream().collect(Collectors.groupingBy(BusErpOrderDetails::getProductCode));
        int a = 0;
        //按商品分组
        for (String a1 : collect1.keySet()) {
            List<BusErpOrderDetails> busErpOrderDetails1a = collect1.get(a1);
            Map<String, List<BusErpOrderDetails>> collect2 = busErpOrderDetails1a.stream().collect(Collectors.groupingBy(BusErpOrderDetails::getDeptName));
            //按部门分组
            for (String a2 : collect2.keySet()) {
                //单位
                //String ZY = "";
                //部门
                String BM = "";
                //商品
                //String SPBH = a1;
                BigDecimal JE = new BigDecimal("0");
                BigDecimal JEv = new BigDecimal("0");
                BigDecimal DJ = new BigDecimal("0");
                BigDecimal DJv = new BigDecimal("0");
                BigDecimal WB = new BigDecimal("0");
                BigDecimal WBv = new BigDecimal("0");
                int SL = 0;
                List<BusErpOrderDetails> busErpOrderDetails1 = collect2.get(a2);
                BusErpOrderDetails busErpOrderDetails = busErpOrderDetails1.get(0);

                for (BusErpOrderDetails erpOrderDetails : busErpOrderDetails1) {
                    SL = SL + erpOrderDetails.getProductNum();
                    //JE = JE.add(erpOrderDetails.getProductSaleAmount());
                }
                //DJ = SL == 0 ? new BigDecimal(SL) : JE.divide(new BigDecimal(SL), BigDecimal.ROUND_CEILING);
                //if (CollUtil.isNotEmpty(productPriceMapList) && null != productPriceMapList.get(a1)) {
                //    DJv = productPriceMapList.get(a1);
                //} else {
                //    DJv = DJ;
                //}
                // 05销项税额科目中商品单价 setSaleAmount      14051 库存商品科目中商品单价  getProductPrice
               /* BigDecimal rate = new BigDecimal(1.13).setScale(2, RoundingMode.HALF_UP);

                if (CollUtil.isNotEmpty(productCodes) && productCodes.contains(busErpOrderDetails.getProductCode())) {
                    //    生物制品的药
                    rate = new BigDecimal(1.03).setScale(2, RoundingMode.HALF_UP);
                }

                DJ = busErpOrderDetails.getProductPrice().divide(rate, BigDecimal.ROUND_CEILING).setScale(2, RoundingMode.HALF_UP);
            */
                //DJ = busErpOrderDetails.getProductPrice();
                DJv = busErpOrderDetails.getSaleAmount();

                //JE = DJ.multiply(new BigDecimal(SL)).setScale(2, RoundingMode.HALF_UP);
                BigDecimal rate = new BigDecimal(1.13).setScale(2, RoundingMode.HALF_UP);

                if (CollUtil.isNotEmpty(productCodes) && productCodes.contains(busErpOrderDetails.getProductCode())) {
                    //    生物制品的药
                    rate = new BigDecimal(1.03).setScale(2, RoundingMode.HALF_UP);
                }

                //JE = DJ.multiply(new BigDecimal(SL)).setScale(2, RoundingMode.HALF_UP).divide(rate, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(0.13)).setScale(2, RoundingMode.HALF_UP) ;
                //JEv = DJv.multiply(new BigDecimal(SL)).setScale(2, RoundingMode.HALF_UP);
                JEv = DJv.multiply(new BigDecimal(SL)).setScale(2, RoundingMode.HALF_UP).divide(rate, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(0.13)).setScale(2, RoundingMode.HALF_UP);
                ZY = busErpOrderDetails.getCompanyName().replaceAll("\\.", "");
                BM = a2;

                LcZWFZYS lcZWFZYS = new LcZWFZYS();
                lcZWFZYS.setZWFZYS_DWBH(DWBH);
                //lcZWFZYS.setZWFZYS_PZNM(PZNM);
                //lcZWFZYS.setZWFZYS_FLNM(IdWorker.get32UUID());

                lcZWFZYS.setZWFZYS_YSBH(String.format("%04d", (a + 1)));
                lcZWFZYS.setZWFZYS_KMBH("");
                // ERP 部门名称
                String bmbh = lcRemoteOrderService.getBMBH(BM, DWBH);
                bmbh = bmbh == null ? lcRemoteOrderService.getBMBH(busErpOrderDetails.getDeptCode(), DWBH) : bmbh;

                lcZWFZYS.setZWFZYS_BMBH(bmbh == null ? "" : bmbh);
                //ERP 单位名称
                //String dwbh = lcRemoteOrderService.getDWBH(ZY);

                //lcZWFZYS.setZWFZYS_WLDWBH(dwbh == null ? "10010404" : dwbh);
                lcZWFZYS.setZWFZYS_ZGBH("");
                lcZWFZYS.setZWFZYS_CPBH("");
                //ERP 商品
                String spbh = lcRemoteOrderService.getSPBH(a1, DWBH);
                lcZWFZYS.setZWFZYS_XMBH(spbh == null ? "" : "000000-" + spbh);
                lcZWFZYS.setZWFZYS_WBBH("01");
                lcZWFZYS.setZWFZYS_JZFX("2");
                lcZWFZYS.setZWFZYS_SL(SL);
                lcZWFZYS.setZWFZYS_DJ(DJ);
                lcZWFZYS.setZWFZYS_DJv(DJv);
                lcZWFZYS.setZWFZYS_WB(WB);
                lcZWFZYS.setZWFZYS_HL("");
                lcZWFZYS.setZWFZYS_JE(JE);
                lcZWFZYS.setZWFZYS_JEv(JEv);
                lcZWFZYS.setZWFZYS_YWRQ(PZRQ);
                lcZWFZYS.setZWFZYS_DWDZ(0);
                lcZWFZYS.setZWFZYS_SJ01(0);
                lcZWFZYS.setZWFZYS_SJ02(0);
                lcZWFZYS.setZWFZYS_SJ03(0);
                lcZWFZYS.setZWFZYS_SJ04(0);
                lcZWFZYS.setZWFZYS_SJ05(0);
                lcZWFZYS.setZWFZYS_YT(ZY);
                lcZWFZYS.setZWFZYS_YHDZ(0);
                lcZWFZYS.setZWFZYS_JSRQ(PZRQ);
                lcZWFZYS.setZWFZYS_ZPDY("0");
                lcZWFZYS.setCreator("");
                //lcZWFZYS.setCreatedTime(DateUtil.now());
                lcZWFZYS.setLastModifier("");
                //lcZWFZYS.setLastModifiedTime(DateUtil.now());
                //lcZWFZYS.setZWFZYS_ID(IdWorker.get32UUID());
                lcZWFZYS.setZWFZYS_BMVersion("1");
                lcZWFZYS.setZWFZYS_WLDWVersion("1");
                lcZWFZYS.setZWFZYS_ZJDJBZ("");
                lcZWFZYS.setZWFZYS_KJLX("0");
                LcZWFZYSSv.add(lcZWFZYS);
            }

        }

        int b = 0;
        //按商品分组
        for (String a1 : collect1.keySet()) {
            List<BusErpOrderDetails> busErpOrderDetails1a = collect1.get(a1);
            Map<String, List<BusErpOrderDetails>> collect2 = busErpOrderDetails1a.stream().collect(Collectors.groupingBy(BusErpOrderDetails::getDeptName));
            //按部门分组
            for (String a2 : collect2.keySet()) {
                //单位
                //String ZY = "";
                //部门
                String BM = "";
                //商品
                //String SPBH = a1;
                BigDecimal JE = new BigDecimal("0");
                BigDecimal JEv = new BigDecimal("0");
                BigDecimal DJ = new BigDecimal("0");
                BigDecimal DJv = new BigDecimal("0");
                BigDecimal WB = new BigDecimal("0");
                BigDecimal WBv = new BigDecimal("0");
                int SL = 0;
                List<BusErpOrderDetails> busErpOrderDetails1 = collect2.get(a2);
                BusErpOrderDetails busErpOrderDetails = busErpOrderDetails1.get(0);

                for (BusErpOrderDetails erpOrderDetails : busErpOrderDetails1) {
                    SL = SL + erpOrderDetails.getProductNum();
                }

                DJ = busErpOrderDetails.getProductPrice();
                //DJv = busErpOrderDetails.getSaleAmount();

                JE = DJ.multiply(new BigDecimal(SL)).setScale(2, RoundingMode.HALF_UP);
                //JEv = DJv.multiply(new BigDecimal(SL)).setScale(2, RoundingMode.HALF_UP);
                ZY = busErpOrderDetails.getCompanyName().replaceAll("\\.", "");
                BM = a2;

                LcZWFZYS lcZWFZYS = new LcZWFZYS();
                lcZWFZYS.setZWFZYS_DWBH(DWBH);

                lcZWFZYS.setZWFZYS_YSBH(String.format("%04d", (b + 1)));
                lcZWFZYS.setZWFZYS_KMBH("");
                // ERP 部门名称
                String bmbh = lcRemoteOrderService.getBMBH(BM, DWBH);
                bmbh = bmbh == null ? lcRemoteOrderService.getBMBH(busErpOrderDetails.getDeptCode(), DWBH) : bmbh;

                lcZWFZYS.setZWFZYS_BMBH(bmbh == null ? "" : bmbh);
                //ERP 单位名称
                //String dwbh = lcRemoteOrderService.getDWBH(ZY);

                //lcZWFZYS.setZWFZYS_WLDWBH(dwbh == null ? "10010404" : dwbh);
                lcZWFZYS.setZWFZYS_ZGBH("");
                lcZWFZYS.setZWFZYS_CPBH("");
                //ERP 商品
                String spbh = lcRemoteOrderService.getSPBH(a1, DWBH);
                lcZWFZYS.setZWFZYS_XMBH(spbh == null ? "" : "000000-" + spbh);
                lcZWFZYS.setZWFZYS_WBBH("01");
                lcZWFZYS.setZWFZYS_JZFX("2");
                lcZWFZYS.setZWFZYS_SL(SL);
                lcZWFZYS.setZWFZYS_DJ(DJ);
                lcZWFZYS.setZWFZYS_DJv(DJv);
                lcZWFZYS.setZWFZYS_WB(WB);
                lcZWFZYS.setZWFZYS_HL("");
                lcZWFZYS.setZWFZYS_JE(JE);
                lcZWFZYS.setZWFZYS_JEv(JEv);
                lcZWFZYS.setZWFZYS_YWRQ(PZRQ);
                lcZWFZYS.setZWFZYS_DWDZ(0);
                lcZWFZYS.setZWFZYS_SJ01(0);
                lcZWFZYS.setZWFZYS_SJ02(0);
                lcZWFZYS.setZWFZYS_SJ03(0);
                lcZWFZYS.setZWFZYS_SJ04(0);
                lcZWFZYS.setZWFZYS_SJ05(0);
                lcZWFZYS.setZWFZYS_YT(ZY);
                lcZWFZYS.setZWFZYS_YHDZ(0);
                lcZWFZYS.setZWFZYS_JSRQ(PZRQ);
                lcZWFZYS.setZWFZYS_ZPDY("0");
                lcZWFZYS.setCreator("");
                //lcZWFZYS.setCreatedTime(DateUtil.now());
                lcZWFZYS.setLastModifier("");
                //lcZWFZYS.setLastModifiedTime(DateUtil.now());
                //lcZWFZYS.setZWFZYS_ID(IdWorker.get32UUID());
                lcZWFZYS.setZWFZYS_BMVersion("1");
                lcZWFZYS.setZWFZYS_WLDWVersion("1");
                lcZWFZYS.setZWFZYS_ZJDJBZ("");
                lcZWFZYS.setZWFZYS_KJLX("0");
                LcZWFZYSS.add(lcZWFZYS);
            }

        }

        // 主记录
        LcZWPZK lcZWPZK = new LcZWPZK();
        lcZWPZK.setZWPZK_DWBH(DWBH);
        //lcZWPZK.setZWPZK_PZNM(PZNM);
        lcZWPZK.setZWPZK_KJND(KJND);
        lcZWPZK.setZWPZK_KJQJ(KJQJ);
        lcZWPZK.setZWPZK_PZRQ(PZRQ);
        lcZWPZK.setZWPZK_PZBH(PZBHStr);
        lcZWPZK.setZWPZK_LXBH("01");
        lcZWPZK.setZWPZK_FJZS(0);
        lcZWPZK.setZWPZK_TYPE(0);
        lcZWPZK.setZWPZK_ZDR(user.getNickName());
        lcZWPZK.setSysUserID(user.getAvatar());
        lcZWPZK.setZWPZK_KJZG("");
        lcZWPZK.setZWPZK_FHF(0);
        lcZWPZK.setZWPZK_JZF(0);
        lcZWPZK.setZWPZK_WZF(1);
        lcZWPZK.setZWPZK_ZFF(0);
        lcZWPZK.setZWPZK_XJDQ(0);
        lcZWPZK.setZWPZK_PZZT(1);
        lcZWPZK.setZWPZK_ZDBZ(0);
        lcZWPZK.setZWPZK_TZDZS(0);
        //lcZWPZK.setZWPZK_ID(IdWorker.get32UUID());
        lcZWPZK.setZWPZK_ZY(DateUtil.now() + "样品");
        BigDecimal je = new BigDecimal(0);
        BigDecimal jev = new BigDecimal(0);
        for (LcZWFZYS zwfzys : LcZWFZYSSv) {
            jev = jev.add(zwfzys.getZWFZYS_JEv());
        }
        for (LcZWFZYS zwfzys : LcZWFZYSS) {
            je = je.add(zwfzys.getZWFZYS_JE());
        }

        lcZWPZK.setZWPZK_JE(je.add(jev));
        lcZWPZK.setCreator("");
        //lcZWPZK.setCreatedTime(DateUtil.now());
        lcZWPZK.setLastModifier("");
        //lcZWPZK.setLastModifiedTime(DateUtil.now());
        lcZWPZK.setZWPZK_DWVersion("1");
        lcZWPZK.setSecretLevelNum("0");
        lcZWPZK.setImageBarCode("");
        lcZWPZK.setImageElecVoucher("");
        lcZWPZK.setZWPZK_DYF("");
        //lcZWPZK.setZWPZK_PZKID(IdWorker.get32UUID());
        lcZWPZK.setZWPZK_ZDRBH(user.getUsername());
        //lcRemoteOrderService.insertZWPZK(lcZWPZK);

        //凭证明细
        List<LcZWPZFL> lcZWPZFLS = new ArrayList<>();
        //660103	销售费用-样品费  部门汇总
        //140501	库存商品-商品    商品为准
        String KMBH11 = "660103", KMBH12 = "140501", KMBH13 = "22210105";
        if(companyId.equals(1017L)){
            KMBH11 = "660103";
            KMBH12 = "140502";
            KMBH13 = "22210105";
        }
        LcZWPZFL lcZWPZFL = new LcZWPZFL();
        lcZWPZFL.setZWPZFL_DWBH(DWBH);
        //lcZWPZFL.setZWPZFL_PZNM(PZNM);
        //lcZWPZFL.setZWPZFL_FLNM(IdWorker.get32UUID());
        lcZWPZFL.setZWPZFL_FLBH("0002");
        lcZWPZFL.setZWPZFL_KMBH(KMBH12);
        lcZWPZFL.setZWPZFL_JSFS("");
        lcZWPZFL.setZWPZFL_ZY("样品");
        lcZWPZFL.setZWPZFL_JE(je);
        lcZWPZFL.setZWPZFL_SL(0);
        lcZWPZFL.setZWPZFL_DJ(new BigDecimal(0));
        lcZWPZFL.setZWPZFL_WB(new BigDecimal(0));
        lcZWPZFL.setZWPZFL_HL(1);
        lcZWPZFL.setZWPZFL_JZFX(2);
        lcZWPZFL.setZWPZFL_DFJE(je);
        lcZWPZFL.setZWPZFL_JFJE(new BigDecimal(0));
        lcZWPZFL.setZWPZFL_WBBH("01");
        lcZWPZFL.setZWPZFL_YHDZ("0");
        //lcZWPZFL.setZWPZFL_ID(IdWorker.get32UUID());
        lcZWPZFL.setCreator("");
        //lcZWPZFL.setCreatedTime(DateUtil.now());
        lcZWPZFL.setLastModifier("");
        //lcZWPZFL.setLastModifiedTime(DateUtil.now());
        lcZWPZFL.setZWPZFL_KJLX("0");
        lcZWPZFL.setZWPZFL_DZZD("");
        lcZWPZFLS.add(lcZWPZFL);
        //科目辅助项
        List<LcZWFZYS> LcZWFZYSS1 = deepCopy(LcZWFZYSS);
        String finalKMBH = KMBH12;
        LcZWFZYSS1.forEach(s1 -> {
            s1.setZWFZYS_KMBH(finalKMBH);
            s1.setZWFZYS_JZFX("2");
            s1.setZWFZYS_FLNM(lcZWPZFL.getZWPZFL_FLNM());
            //s1.setZWFZYS_JE(s1.getZWFZYS_JEv());
            //s1.setZWFZYS_DJ(s1.getZWFZYS_DJv());
            //s1.setZWFZYS_ID(IdWorker.get32UUID());
        });


        LcZWPZFL lcZWPZFL2 = new LcZWPZFL();
        lcZWPZFL2.setZWPZFL_DWBH(DWBH);
        //lcZWPZFL2.setZWPZFL_PZNM(PZNM);
        //lcZWPZFL2.setZWPZFL_FLNM(IdWorker.get32UUID());
        lcZWPZFL2.setZWPZFL_FLBH("0001");
        lcZWPZFL2.setZWPZFL_KMBH(KMBH11);
        lcZWPZFL2.setZWPZFL_JSFS("");

        List<LcZWFZYS> LcZWFZYSS2 = new ArrayList<>();
        LcZWFZYSS.addAll(LcZWFZYSSv);
        Map<String, List<LcZWFZYS>> bms = LcZWFZYSS.stream().filter(i -> i.getZWFZYS_BMBH() != null).collect(Collectors.groupingBy(LcZWFZYS::getZWFZYS_BMBH));
        int it = 0;
        for (String bm : bms.keySet()) {
            List<LcZWFZYS> lcZWFZYS_ = bms.get(bm);
            it++;
            LcZWFZYS lcZWFZYS = new LcZWFZYS();
            lcZWFZYS.setZWFZYS_DWBH(DWBH);
            //lcZWFZYS.setZWFZYS_PZNM(PZNM);
            lcZWFZYS.setZWFZYS_FLNM(lcZWPZFL2.getZWPZFL_FLNM());
            lcZWFZYS.setZWFZYS_YSBH(String.format("%04d", (it)));
            lcZWFZYS.setZWFZYS_KMBH(KMBH11);
            // ERP 部门名称
            //String bmbh = lcRemoteOrderService.getBMBH(bm);
            lcZWFZYS.setZWFZYS_BMBH(bm);

            //ERP 单位名称
            //String dwbh = lcRemoteOrderService.getDWBH(ZY);
            //lcZWFZYS.setZWFZYS_WLDWBH(dwbh == null ? "10010404" : dwbh);

            lcZWFZYS.setZWFZYS_ZGBH("");
            lcZWFZYS.setZWFZYS_CPBH("");
            lcZWFZYS.setZWFZYS_XMBH("");
            //ERP 商品
            //String spbh = lcRemoteOrderService.getSPBH(SPBH, DWBH);
            //lcZWFZYS.setZWFZYS_XMBH("000000-" + spbh == null ? "000064" : spbh);
            lcZWFZYS.setZWFZYS_WBBH("01");
            lcZWFZYS.setZWFZYS_JZFX("1");
            lcZWFZYS.setZWFZYS_SL(lcZWFZYS_.stream().map(LcZWFZYS::getZWFZYS_SL).mapToInt(i -> i).sum());

            lcZWFZYS.setZWFZYS_DJ(new BigDecimal(0));
            lcZWFZYS.setZWFZYS_WB(new BigDecimal(0));
            //lcZWFZYS.setZWFZYS_DJ(new BigDecimal(lcZWFZYS_.stream().map(LcZWFZYS::getZWFZYS_DJ).mapToDouble(b -> b).sum()));
            //lcZWFZYS.setZWFZYS_WB(new BigDecimal(lcZWFZYS_.stream().map(LcZWFZYS::getZWFZYS_WB).mapToDouble(b -> b).sum()));
            lcZWFZYS.setZWFZYS_HL("");
            BigDecimal je2 = new BigDecimal(0);
            BigDecimal je2v = new BigDecimal(0);
            for (LcZWFZYS zwfzys : lcZWFZYS_) {
                je2 = je2.add(zwfzys.getZWFZYS_JE()).add(zwfzys.getZWFZYS_JEv());
                je2v = je2.add(zwfzys.getZWFZYS_JE()).add(zwfzys.getZWFZYS_JEv());
            }
            lcZWFZYS.setZWFZYS_JE(je2.setScale(2, RoundingMode.HALF_UP));
            lcZWFZYS.setZWFZYS_JEv(je2.setScale(2, RoundingMode.HALF_UP));
            lcZWFZYS.setZWFZYS_YWRQ(PZRQ);
            lcZWFZYS.setZWFZYS_DWDZ(0);
            lcZWFZYS.setZWFZYS_SJ01(0);
            lcZWFZYS.setZWFZYS_SJ02(0);
            lcZWFZYS.setZWFZYS_SJ03(0);
            lcZWFZYS.setZWFZYS_SJ04(0);
            lcZWFZYS.setZWFZYS_SJ05(0);
            lcZWFZYS.setZWFZYS_YT("");
            lcZWFZYS.setZWFZYS_YHDZ(0);
            lcZWFZYS.setZWFZYS_JSRQ(PZRQ);
            lcZWFZYS.setZWFZYS_ZPDY("0");
            lcZWFZYS.setCreator("");
            //lcZWFZYS.setCreatedTime(DateUtil.now());
            lcZWFZYS.setLastModifier("");
            //lcZWFZYS.setLastModifiedTime(DateUtil.now());
            //lcZWFZYS.setZWFZYS_ID(IdWorker.get32UUID());
            lcZWFZYS.setZWFZYS_BMVersion("1");
            lcZWFZYS.setZWFZYS_WLDWVersion("1");
            lcZWFZYS.setZWFZYS_ZJDJBZ("");
            lcZWFZYS.setZWFZYS_KJLX("0");
            LcZWFZYSS2.add(lcZWFZYS);
        }
        lcZWPZFL2.setZWPZFL_ZY("样品");
        BigDecimal JE2 = new BigDecimal(0);
        BigDecimal JE2v = new BigDecimal(0);
        for (LcZWFZYS lcZWFZYS : LcZWFZYSS2) {
            JE2 = JE2.add(lcZWFZYS.getZWFZYS_JE());
            JE2v = JE2v.add(lcZWFZYS.getZWFZYS_JEv());
        }
        lcZWPZFL2.setZWPZFL_JE(JE2);
        lcZWPZFL2.setZWPZFL_SL(0);
        lcZWPZFL2.setZWPZFL_DJ(new BigDecimal(0));
        lcZWPZFL2.setZWPZFL_WB(new BigDecimal(0));
        lcZWPZFL2.setZWPZFL_HL(1);
        lcZWPZFL2.setZWPZFL_JZFX(1);

        lcZWPZFL2.setZWPZFL_JFJE(JE2);
        lcZWPZFL2.setZWPZFL_DFJE(new BigDecimal(0));
        lcZWPZFL2.setZWPZFL_WBBH("01");
        lcZWPZFL2.setZWPZFL_YHDZ("0");
        //lcZWPZFL2.setZWPZFL_ID(IdWorker.get32UUID());
        lcZWPZFL2.setCreator("");
        //lcZWPZFL2.setCreatedTime(DateUtil.now());
        lcZWPZFL2.setLastModifier("");
        //lcZWPZFL2.setLastModifiedTime(DateUtil.now());
        lcZWPZFL2.setZWPZFL_KJLX("0");
        lcZWPZFL2.setZWPZFL_DZZD("");
        lcZWPZFLS.add(lcZWPZFL2);

        //22210105	应交税费-应交增值税-销项税额
        LcZWPZFL lcZWPZFL3 = new LcZWPZFL();
        lcZWPZFL3.setZWPZFL_DWBH(DWBH);
        //lcZWPZFL3.setZWPZFL_PZNM(PZNM);
        //lcZWPZFL3.setZWPZFL_FLNM(IdWorker.get32UUID());
        lcZWPZFL3.setZWPZFL_FLBH("0003");
        lcZWPZFL3.setZWPZFL_KMBH(KMBH13);
        lcZWPZFL3.setZWPZFL_JSFS("");
        lcZWPZFL3.setZWPZFL_ZY("样品");
        lcZWPZFL3.setZWPZFL_SL(0);
        lcZWPZFL3.setZWPZFL_DJ(new BigDecimal(0));
        lcZWPZFL3.setZWPZFL_WB(new BigDecimal(0));
        lcZWPZFL3.setZWPZFL_HL(1);

        lcZWPZFL3.setZWPZFL_JZFX(2);

        lcZWPZFL3.setZWPZFL_WBBH("01");
        lcZWPZFL3.setZWPZFL_YHDZ("0");
        //lcZWPZFL3.setZWPZFL_ID(IdWorker.get32UUID());
        lcZWPZFL3.setCreator("");
        //lcZWPZFL3.setCreatedTime(DateUtil.now());
        lcZWPZFL3.setLastModifier("");
        //lcZWPZFL3.setLastModifiedTime(DateUtil.now());
        lcZWPZFL3.setZWPZFL_KJLX("0");
        lcZWPZFL3.setZWPZFL_DZZD("");

        //List<LcZWFZYS> LcZWFZYSS3 = LcZWFZYSS.stream().collect(Collectors.toList());
        //List<LcZWFZYS> LcZWFZYSS3 = deepCopy(LcZWFZYSSv);
        //List<LcZWFZYS> LcZWFZYSST = deepCopy(LcZWFZYSS);
        List<LcZWFZYS> LcZWFZYSS3 = new ArrayList<>();

        Map<String, List<LcZWFZYS>> bmst = LcZWFZYSSv.stream().filter(i -> i.getZWFZYS_BMBH() != null).collect(Collectors.groupingBy(LcZWFZYS::getZWFZYS_BMBH));
        for (String s : bmst.keySet()) {
            List<LcZWFZYS> lcZWFZYS = bmst.get(s);
            LcZWFZYS aaa = lcZWFZYS.get(0);
            aaa.setZWFZYS_JE(aaa.getZWFZYS_JEv());

            if (lcZWFZYS.size() > 1) {
                for (int i = 1; i < lcZWFZYS.size(); i++) {
                    LcZWFZYS lcZWFZYS1 = lcZWFZYS.get(i);
                    aaa.setZWFZYS_JE(aaa.getZWFZYS_JE().add(lcZWFZYS1.getZWFZYS_JEv()));
                }
            }

            LcZWFZYSS3.add(aaa);

        }

        BigDecimal JE3 = new BigDecimal(0);


        for (LcZWFZYS s3 : LcZWFZYSS3) {
            s3.setZWFZYS_KMBH(KMBH13);
            s3.setZWFZYS_JZFX("2");
            s3.setZWFZYS_FLNM(lcZWPZFL3.getZWPZFL_FLNM());
            //s3.setZWFZYS_ID(IdWorker.get32UUID());

            s3.setZWFZYS_JE(s3.getZWFZYS_JE());
            JE3 = JE3.add(s3.getZWFZYS_JE());
        }


        lcZWPZFL3.setZWPZFL_DFJE(JE3);
        lcZWPZFL3.setZWPZFL_JFJE(new BigDecimal(0));
        lcZWPZFL3.setZWPZFL_JE(JE3);
        lcZWPZFLS.add(lcZWPZFL3);

        //lcRemoteOrderService.insertZWPZFL(lcZWPZFLS);
        //lcRemoteOrderService.insertZWFZYS(LcZWFZYSS3);
        //lcRemoteOrderService.insertZWFZYS(LcZWFZYSS2);
        //lcRemoteOrderService.insertZWFZYS(LcZWFZYSS1);


        lcZWPZFL3.setVoucherfzhs(LcZWFZYSS3);
        lcZWPZFL2.setVoucherfzhs(LcZWFZYSS2);
        lcZWPZFL.setVoucherfzhs(LcZWFZYSS1);
        //lcZWPZFLS.add(lcZWPZFL3);
        //lcZWPZFLS.add(lcZWPZFL2);
        //lcZWPZFLS.add(lcZWPZFL);
        lcZWPZK.setVoucherfl(lcZWPZFLS);

        JSONObject obj = JSONUtil.createObj();
        obj.set("voucherHead", lcZWPZK);

        String s = JSONUtil.toJsonStr(obj);
        System.out.println("#########################凭证参数:"+s);
        log.info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@凭证参数",s);
        if(isOnline) {
            String result = HttpUtil.post(lcApi, s);

            JSONObject jsonObject = JSONUtil.parseObj(result);
            if ("200".equals(jsonObject.getStr("code"))) {
                String data = jsonObject.get("data").toString();

                JSONObject objData = JSONUtil.parseObj(data);
                Object savedVochers = objData.get("SavedVochers");
                int state = 0;
                String voucher = "";

                if (objData.get("FailedVochers").toString().length() > 3) {
                    savedVochers = objData.get("FailedVochers");
                    voucher = savedVochers.toString();
                    state = 3;

                } else {
                    savedVochers = savedVochers.toString().substring(savedVochers.toString().indexOf("#") + 1, savedVochers.toString().indexOf("#") + 6);
                    state = 1;
                    voucher = currentDay + " " + savedVochers;
                }

                hyRemoteOrderService.updateYpVocher(dbName, state, voucher, StrUtil.split(orderNo, ','));
            } else {
                hyRemoteOrderService.updateYpVocher(dbName, 3, "", StrUtil.split(orderNo, ','));
            }
            /*busErpOrderService.update(new UpdateWrapper<BusErpOrder>().lambda().set(BusErpOrder::getVoucherJSON, s + result).set(BusErpOrder::getUpdateTime, DateUtil.date()).set(BusErpOrder::getVoucherHandleState, state).set(BusErpOrder::getVoucher, voucher).eq(BusErpOrder::getOrderType, VoucherTypeEnum.Yp.getCode()).in(BusErpOrder::getOrderNo, busErpOrderDetailsList.stream().map(BusErpOrderDetails::getOrderNo).collect(Collectors.toList())));
            List<BusErpOrder> list = busErpOrderService.list(new QueryWrapper<BusErpOrder>().lambda().eq(BusErpOrder::getOrderType, orderType).in(BusErpOrder::getOrderNo, StrUtil.split(orderNo, ',')));
            for (BusErpOrder busErpOrder : list) {
                busErpOrder.setVoucherCount(busErpOrder.getVoucherCount() + 1);
            }
            busErpOrderService.saveOrUpdateBatch(list);
        } else {
            busErpOrderService.update(new UpdateWrapper<BusErpOrder>().lambda().set(BusErpOrder::getVoucherJSON, s + result).set(BusErpOrder::getUpdateTime, DateUtil.date()).set(BusErpOrder::getVoucherHandleState, 3).set(BusErpOrder::getVoucher, jsonObject.getStr("msg")).eq(BusErpOrder::getOrderType, VoucherTypeEnum.Yp.getCode()).in(BusErpOrder::getOrderNo, busErpOrderDetailsList.stream().map(BusErpOrderDetails::getOrderNo).collect(Collectors.toList())));
            List<BusErpOrder> list = busErpOrderService.list(new QueryWrapper<BusErpOrder>().lambda().eq(BusErpOrder::getOrderType, orderType).in(BusErpOrder::getOrderNo, StrUtil.split(orderNo, ',')));
            for (BusErpOrder busErpOrder : list) {
                busErpOrder.setVoucherCount(busErpOrder.getVoucherCount() + 1);
            }
            busErpOrderService.saveOrUpdateBatch(list);
        }*/
        }

    }

    /**
     * 对集合进行深拷贝
     * 注意需要岁泛型类进行序列化（实现serializable）
     *
     * @param src
     * @return
     * @throws ClassNotFoundException
     */
    List<LcZWFZYS> deepCopy(List<LcZWFZYS> src) {
        try (ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
             ObjectOutputStream outputStream = new ObjectOutputStream(byteOut)
        ) {
            outputStream.writeObject(src);
            try (ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
                 ObjectInputStream inputStream = new ObjectInputStream(byteIn)
            ) {
                return (List<LcZWFZYS>) inputStream.readObject();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Collections.emptyList();
    }


    @Override
    @Async("voucherExecutor")
    public void sampleVoucher(String month, List<BusErpOrderDetails> productList, OpenUser user) {
        Long companyId = user.getCompanyId();
        List<String> bhList = productList.stream().map(BusErpOrderDetails::getProductCode).collect(Collectors.toList());
        String dwCode = busCwErpService.getById(companyId).getCompanyCode();
        //查找商品编码
        List<EntityMap> productCodeList = lcRemoteOrderService.getSPBHList(dwCode, bhList);


        List<SysCompany> companyList = busCwErpService.list(new QueryWrapper<SysCompany>().lambda().eq(SysCompany::getCompanyErpState, 1).eq(SysCompany::getCompanyId, companyId));
        busErpOrderService.remove(new QueryWrapper<BusErpOrder>().lambda().eq(BusErpOrder::getOrderType, VoucherTypeEnum.Yp.getCode()).likeRight(BusErpOrder::getOrderDate, month));
        busErpOrderDetailsService.remove(new QueryWrapper<BusErpOrderDetails>().lambda().eq(BusErpOrderDetails::getOrderType, VoucherTypeEnum.Yp.getCode()).likeRight(BusErpOrderDetails::getOrderDate, month));


        for (SysCompany company : companyList) {

            //List<EntityMap> productLists = hyRemoteOrderService.getProductByType(company.getCompanyErpInstance(), "生物制品");

            //List<String> productCodes = productLists.stream().map(i -> i.get("productCode").toString()).collect(Collectors.toList());

            //替换商品编码
            for (BusErpOrderDetails details : productList) {
                for (EntityMap entityMap : productCodeList) {
                    if (ObjectUtil.isNotNull(entityMap.get("LSHSXM_XMNM"))) {
                        if (details.getProductCode().equals(entityMap.get("LSHSXM_XMNM").toString())) {
                            if (ObjectUtil.isNotNull(entityMap.get("LSHSXM_XMJC"))) {
                                details.setProductCode(entityMap.get("LSHSXM_XMJC"));
                              /*  BigDecimal rate = new BigDecimal(1.13).setScale(2, RoundingMode.HALF_UP);

                                if (CollUtil.isNotEmpty(productCodes) && productCodes.contains(details.getProductCode())) {
                                    //    生物制品的药
                                    rate = new BigDecimal(1.03).setScale(2, RoundingMode.HALF_UP);
                                }
                                details.setProductPrice(details.getProductPrice().divide(rate, BigDecimal.ROUND_HALF_UP).setScale(2, RoundingMode.HALF_UP));
                              */
                                break;
                            }
                        }
                    }
                }
            }

            //查询当月其他出库单
            List<EntityMap> orderList = hyRemoteOrderService.sampleOrderList(company.getCompanyErpInstance(), month);
            if (CollUtil.isEmpty(orderList)) {
                return;
            }
            List<BusErpOrder> busErpOrderList = new ArrayList<>();
            orderList.forEach(item -> {
                JSONObject obj = new JSONObject();
                obj.putAll(item);
                BusErpOrder busErpOrder = obj.toBean(BusErpOrder.class);
                busErpOrder.setOrderType(VoucherTypeEnum.Yp.getCode());
                busErpOrder.setErpDbName(company.getCompanyErpInstance());
                busErpOrder.setHyDwCode(dwCode);
                busErpOrder.setCompanyId(company.getCompanyId());
                busErpOrderList.add(busErpOrder);
            });
            busErpOrderService.saveBatch(busErpOrderList);

            Map<String, BigDecimal> productPriceMapList = productList.stream().collect(Collectors.toMap(BusErpOrderDetails::getProductCode, (s -> s.getProductPrice())));
            Map<String, String> productCodeMapList = productList.stream().collect(Collectors.toMap(BusErpOrderDetails::getProductCode, (s -> s.getProductCodeSource())));

            //List<EntityMap> orderDetailList = hyRemoteOrderService.sampleOrderDetailList(dbName, "2023-02-24");
            List<EntityMap> orderDetailList = hyRemoteOrderService.sampleOrderDetailList(company.getCompanyErpInstance(), month);

            //    查询当月销售订单
            List<EntityMap> orderList1 = hyRemoteOrderService.saleOrderDetail(company.getCompanyErpInstance(), month, orderDetailList.stream().map(i -> i.get("productCode").toString()).collect(Collectors.toList()));
            Map<String, List<EntityMap>> collect = orderList1.stream().collect(Collectors.groupingBy(a -> a.get("productCode").toString()));

            List<BusErpOrderDetails> busErpOrderDetailsList = new ArrayList<>();
            List<String> pCode = new ArrayList<>();
            orderDetailList.forEach(item -> {
                JSONObject obj = new JSONObject();
                obj.putAll(item);
                BusErpOrderDetails busErpOrderDetails = obj.toBean(BusErpOrderDetails.class);
                String BM = (Character.isLowerCase(busErpOrderDetails.getSaleManName().charAt(0)) || Character.isUpperCase(busErpOrderDetails.getSaleManName().charAt(0))) ? busErpOrderDetails.getSaleManName() : busErpOrderDetails.getDeptName();
                BM = BM.indexOf("商务") != -1 ? "Z" + getNumeric(BM) : BM;
                busErpOrderDetails.setDeptName(BM);
                busErpOrderDetails.setOrderType(VoucherTypeEnum.Yp.getCode());
                busErpOrderDetails.setErpDbName(company.getCompanyErpInstance());
                busErpOrderDetails.setHyDwCode(dwCode);
                if (CollUtil.isNotEmpty(productPriceMapList)) {
                    for (String s : productPriceMapList.keySet()) {

                        if (s.contains(busErpOrderDetails.getProductCode())) {
                            BigDecimal ypdj = productPriceMapList.get(s);
                            busErpOrderDetails.setProductPrice(ypdj);
                            busErpOrderDetails.setProductCodeSource(productCodeMapList.get(s));
                            break;
                        }
                    }

                    //String s1 = productPriceMapList.keySet().stream().filter(s -> s.indexOf(busErpOrderDetails.getProductCode()) != -1).findFirst().get();


                }
                if (CollUtil.isNotEmpty(collect.get(busErpOrderDetails.getProductCode()))) {
                    List<EntityMap> entityMaps = collect.get(busErpOrderDetails.getProductCode());

                    BigDecimal sl = new BigDecimal(0);
                    BigDecimal je = new BigDecimal(0);
                    BigDecimal dj = new BigDecimal(0);
                    for (EntityMap entityMap : entityMaps) {

                         /* BigDecimal rate = new BigDecimal(1.13).setScale(2, RoundingMode.HALF_UP);

                                if (CollUtil.isNotEmpty(productCodes) && productCodes.contains(busErpOrderDetails.getProductCode())) {
                                    //    生物制品的药
                                    rate = new BigDecimal(1.03).setScale(2, RoundingMode.HALF_UP);
                                }
                                je = je.add(entityMap.getBigDecimal("productSaleAmount").divide(rate, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(0.13)).setScale(2, RoundingMode.HALF_UP) );
                               */
                        je = je.add(entityMap.getBigDecimal("productSaleAmount"));
                        sl = sl.add(entityMap.get("productNum"));
                    }
                    dj = sl.intValue() == 0 ? dj : je.divide(sl, 2, BigDecimal.ROUND_HALF_UP);
                    busErpOrderDetails.setSaleAmount(dj);
                } else {
                    Map<String, BigDecimal> map = new HashMap<>();

                    map.put(busErpOrderDetails.getProductCode(), new BigDecimal(0));
                    recursionOrder(company.getCompanyErpInstance(), busErpOrderDetails.getOrderDate(), map);

                   /* BigDecimal rate = new BigDecimal(1.13).setScale(2, RoundingMode.HALF_UP);

                    if (CollUtil.isNotEmpty(productCodes) && productCodes.contains(busErpOrderDetails.getProductCode())) {
                        //    生物制品的药
                        rate = new BigDecimal(1.03).setScale(2, RoundingMode.HALF_UP);
                    }


                    busErpOrderDetails.setSaleAmount( map.get(busErpOrderDetails.getProductCode()).divide(rate, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(0.13)).setScale(2, RoundingMode.HALF_UP) );
*/
                    busErpOrderDetails.setSaleAmount(map.get(busErpOrderDetails.getProductCode()));
                    //pCode.add(  busErpOrderDetails.getProductCode());

                }
                busErpOrderDetailsList.add(busErpOrderDetails);
            });


            busErpOrderDetailsService.saveBatch(busErpOrderDetailsList);


        }


        /*String currentDay = DatePattern.NORM_DATE_FORMAT.format(DateUtil.date());
        currentDay = "2022-08-31";

        String DWBH = companyCode, KJND = currentDay.split("-")[0], KJQJ = currentDay.split("-")[1];
        String PZRQ = currentDay.replaceAll("-", "");
        // 凭证号
        int PZBH = 1;
        EntityMap zwpzbh = lcRemoteOrderService.getZWPZBH(DWBH, KJND, KJQJ);
        String PZNM = lcRemoteOrderService.getMaxPZNM() + 1 + "";
        if (CollUtil.isEmpty(zwpzbh)) {
            LcZWPZBH lcZWPZBH = new LcZWPZBH();
            lcZWPZBH.setZWPZBH_DWBH(DWBH);
            lcZWPZBH.setZWPZBH_KJND(KJND);
            lcZWPZBH.setZWPZBH_KJQJ(KJQJ);
            lcZWPZBH.setZWPZBH_PZZ("0");
            lcZWPZBH.setZWPZBH_PZRQ(PZRQ);
            lcZWPZBH.setCreator("");
            lcZWPZBH.setCreatedTime(DateUtil.now());
            lcZWPZBH.setZWPZBH_ID(IdWorker.get32UUID());
            lcZWPZBH.setZWPZBH_PZBH(PZBH);
            List<LcZWPZBH> lcZWPZBHList = new ArrayList<>();
            lcZWPZBHList.add(lcZWPZBH);
            lcRemoteOrderService.insertZWPZBH(lcZWPZBHList);
        } else {
            Integer zwpzbh_pzbh = zwpzbh.getInt("ZWPZBH_PZBH");
            PZBH = zwpzbh_pzbh + 1;
            lcRemoteOrderService.changeZWPZBH(DWBH, KJND, KJQJ, PZBH, PZRQ);
        }

        String PZBHStr = String.format("%05d", PZBH);*/
    }

    void recursionOrder(String dbName, String month, Map<String, BigDecimal> map) {
        String productCode = map.keySet().iterator().next();
        String substring = DateUtil.format(DateUtil.offsetMonth(DateUtil.parse(month.replace("-", "")), -1), DatePattern.NORM_DATETIME_PATTERN).substring(0, 7);
        List<EntityMap> orderList1 = hyRemoteOrderService.saleOrderDetail(dbName, substring, Arrays.asList(productCode));

        if (CollUtil.isNotEmpty(orderList1)) {
            Map<String, List<EntityMap>> stringListMap = orderList1.stream().collect(Collectors.groupingBy(a -> a.get("productCode").toString()));

            List<EntityMap> entityMaps = stringListMap.get(productCode);

            BigDecimal sl = new BigDecimal(0);
            BigDecimal je = new BigDecimal(0);
            for (EntityMap entityMap : entityMaps) {
                je = je.add(entityMap.get("productSaleAmount"));
                sl = sl.add(entityMap.get("productNum"));
            }
            map.put(productCode, sl.intValue() == 0 ? new BigDecimal(0) : je.divide(sl, 2, BigDecimal.ROUND_HALF_UP));
        } else {
            String tmp = substring.substring(0, 4) + "-" + substring.substring(5) + "-01";
            recursionOrder(dbName, tmp, map);
        }
    }

    @Override
    @Async("voucherExecutor")
    public void costVoucher(Map params) {

    }

    @Override
    @Async("voucherExecutor")
    public void createPayment(Map params) {

    }

    @Override
    //@Async("voucherExecutor")
    public void updateOrder(Map params) {
        Integer orderType = MapUtil.getInt(params, "orderType");
        String orderNo = MapUtil.getStr(params, "orderNo");
        String hyDwCode = MapUtil.getStr(params, "hyDwCode");
        String startDay = MapUtil.getStr(params, "beginDate");
        String endDay = MapUtil.getStr(params, "endDate");

        if (StrUtil.isEmpty(startDay)) {
            //销售
            if (orderType.equals(VoucherTypeEnum.Xs.getCode())) {
                busErpOrderDetailsService.remove(new QueryWrapper<BusErpOrderDetails>().lambda().eq(BusErpOrderDetails::getOrderNo, orderNo).eq(BusErpOrderDetails::getOrderType, orderType));
                BusErpOrder one = busErpOrderService.getOne(new QueryWrapper<BusErpOrder>().lambda().eq(BusErpOrder::getOrderNo, orderNo).eq(BusErpOrder::getOrderType, orderType));
                List<EntityMap> list = hyRemoteOrderService.saleOrderList(one.getErpDbName(), DateUtil.format(one.getCreateTime(), DatePattern.NORM_DATE_PATTERN), one.getOrderNo());
                if (CollUtil.isNotEmpty(list)) {
                    List<BusErpOrder> busErpOrderList = new ArrayList<>();
                    list.forEach(item -> {
                        BusErpOrder busErpOrder = BeanUtil.fillBeanWithMap(item, new BusErpOrder(), false);
                        BusErpOrder check = busErpOrderService.findByOrderNoAndType(busErpOrder.getOrderNo(), orderType);
                        if (FlymeUtils.isNotEmpty(check)) {
                            busErpOrder.setOrderId(check.getOrderId());
                        }
                        busErpOrder.setOrderType(VoucherTypeEnum.Xs.getCode());
                        busErpOrder.setErpDbName(one.getErpDbName());
                        busErpOrder.setHyDwCode(one.getHyDwCode());
                        busErpOrder.setCompanyId(one.getCompanyId());
                        busErpOrder.setVoucherCount(one.getVoucherCount());
                        busErpOrder.setVoucher(one.getVoucher());
                        busErpOrder.setVoucherHandleState(one.getVoucherHandleState());
                        busErpOrderList.add(busErpOrder);
                    });
                    busErpOrderService.saveOrUpdateBatch(busErpOrderList);
                    busErpOrderDetailsService.remove(new QueryWrapper<BusErpOrderDetails>().lambda().eq(BusErpOrderDetails::getOrderNo, orderNo).eq(BusErpOrderDetails::getOrderType, VoucherTypeEnum.Xs.getCode()));
                    List<EntityMap> orderDetailList = hyRemoteOrderService.saleOrderDetailList(one.getErpDbName(), DateUtil.format(one.getCreateTime(), DatePattern.NORM_DATE_PATTERN), one.getOrderNo());
                    List<BusErpOrderDetails> busErpOrderDetailsList = new ArrayList<>();
                    orderDetailList.forEach(item -> {
                        BusErpOrderDetails busErpOrderDetails = BeanUtil.fillBeanWithMap(item, new BusErpOrderDetails(), false);
                        busErpOrderDetails.setOrderType(VoucherTypeEnum.Xs.getCode());
                        busErpOrderDetails.setErpDbName(one.getErpDbName());
                        busErpOrderDetails.setHyDwCode(one.getHyDwCode());
                        busErpOrderDetailsList.add(busErpOrderDetails);
                    });
                    busErpOrderDetailsService.saveBatch(busErpOrderDetailsList);
                }
                //busErpOrderService.removeById(one.getOrderId());
            }
            //    采购
            if (orderType.equals(VoucherTypeEnum.Cg.getCode())) {
                busErpOrderDetailsService.remove(new QueryWrapper<BusErpOrderDetails>().lambda().eq(BusErpOrderDetails::getOrderNo, orderNo).eq(BusErpOrderDetails::getOrderType, orderType));
                BusErpOrder one = busErpOrderService.getOne(new QueryWrapper<BusErpOrder>().lambda().eq(BusErpOrder::getOrderNo, orderNo).eq(BusErpOrder::getOrderType, orderType));
                List<EntityMap> list = hyRemoteOrderService.buyOrderList(one.getErpDbName(), DateUtil.format(one.getCreateTime(), DatePattern.NORM_DATE_PATTERN), one.getOrderNo());
                if (CollUtil.isNotEmpty(list)) {

                    List<BusErpOrder> busErpOrderList = new ArrayList<>();
                    list.forEach(item -> {
                        BusErpOrder busErpOrder = BeanUtil.fillBeanWithMap(item, new BusErpOrder(), false);
                        BusErpOrder check = busErpOrderService.findByOrderNoAndType(busErpOrder.getOrderNo(), orderType);
                        if (FlymeUtils.isNotEmpty(check)) {
                            busErpOrder.setOrderId(check.getOrderId());
                        }
                        busErpOrder.setOrderType(VoucherTypeEnum.Cg.getCode());
                        busErpOrder.setErpDbName(one.getErpDbName());
                        busErpOrder.setHyDwCode(one.getHyDwCode());
                        busErpOrder.setCompanyId(one.getCompanyId());
                        busErpOrder.setVoucherCount(one.getVoucherCount());
                        busErpOrder.setVoucher(one.getVoucher());
                        busErpOrder.setVoucherHandleState(one.getVoucherHandleState());
                        busErpOrderList.add(busErpOrder);
                    });
                    busErpOrderService.saveOrUpdateBatch(busErpOrderList);

                    busErpOrderDetailsService.remove(new QueryWrapper<BusErpOrderDetails>().lambda().eq(BusErpOrderDetails::getOrderNo, orderNo).eq(BusErpOrderDetails::getOrderType, VoucherTypeEnum.Cg.getCode()));
                    List<EntityMap> orderDetailList = hyRemoteOrderService.buyOrderDetailList(one.getErpDbName(), DateUtil.format(one.getCreateTime(), DatePattern.NORM_DATE_PATTERN), one.getOrderNo());
                    List<BusErpOrderDetails> busErpOrderDetailsList = new ArrayList<>();
                    orderDetailList.forEach(item -> {
                        BusErpOrderDetails busErpOrderDetails = BeanUtil.fillBeanWithMap(item, new BusErpOrderDetails(), false);
                        busErpOrderDetails.setOrderType(VoucherTypeEnum.Cg.getCode());
                        busErpOrderDetails.setErpDbName(one.getErpDbName());
                        busErpOrderDetails.setHyDwCode(one.getHyDwCode());
                        busErpOrderDetailsList.add(busErpOrderDetails);
                    });

                    busErpOrderDetailsService.saveOrUpdateBatch(busErpOrderDetailsList);
                }
                //busErpOrderService.removeById(one.getOrderId());

            }
            //    成本
            if (orderType.equals(VoucherTypeEnum.Cb.getCode())) {
                busErpOrderDetailsService.remove(new QueryWrapper<BusErpOrderDetails>().lambda().eq(BusErpOrderDetails::getOrderNo, orderNo).eq(BusErpOrderDetails::getOrderType, orderType));
                BusErpOrder one = busErpOrderService.getOne(new QueryWrapper<BusErpOrder>().lambda().eq(BusErpOrder::getOrderNo, orderNo).eq(BusErpOrder::getOrderType, orderType));
                List<EntityMap> list = hyRemoteOrderService.saleCostList(one.getErpDbName(), DateUtil.format(one.getCreateTime(), DatePattern.NORM_DATE_PATTERN), one.getOrderNo());
                if (CollUtil.isNotEmpty(list)) {

                    List<BusErpOrder> busErpOrderList = new ArrayList<>();
                    list.forEach(item -> {
                        BusErpOrder busErpOrder = BeanUtil.fillBeanWithMap(item, new BusErpOrder(), false);
                        BusErpOrder check = busErpOrderService.findByOrderNoAndType(busErpOrder.getOrderNo(), orderType);
                        if (FlymeUtils.isNotEmpty(check)) {
                            busErpOrder.setOrderId(check.getOrderId());
                        }
                        busErpOrder.setOrderType(VoucherTypeEnum.Cb.getCode());
                        busErpOrder.setErpDbName(one.getErpDbName());
                        busErpOrder.setHyDwCode(one.getHyDwCode());
                        busErpOrder.setCompanyId(one.getCompanyId());
                        busErpOrder.setVoucherCount(one.getVoucherCount());
                        busErpOrder.setVoucher(one.getVoucher());
                        busErpOrder.setVoucherHandleState(one.getVoucherHandleState());
                        busErpOrderList.add(busErpOrder);
                    });
                    busErpOrderService.saveOrUpdateBatch(busErpOrderList);
                    busErpOrderDetailsService.remove(new QueryWrapper<BusErpOrderDetails>().lambda().eq(BusErpOrderDetails::getOrderNo, orderNo).eq(BusErpOrderDetails::getOrderType, VoucherTypeEnum.Cb.getCode()));
                    List<EntityMap> orderDetailList = hyRemoteOrderService.saleCostDetailList(one.getErpDbName(), DateUtil.format(one.getCreateTime(), DatePattern.NORM_DATE_PATTERN), one.getOrderNo());
                    List<BusErpOrderDetails> busErpOrderDetailsList = new ArrayList<>();
                    orderDetailList.forEach(item -> {
                        BusErpOrderDetails busErpOrderDetails = BeanUtil.fillBeanWithMap(item, new BusErpOrderDetails(), false);
                        busErpOrderDetails.setOrderType(VoucherTypeEnum.Cb.getCode());
                        busErpOrderDetails.setErpDbName(one.getErpDbName());
                        busErpOrderDetails.setHyDwCode(one.getHyDwCode());
                        busErpOrderDetailsList.add(busErpOrderDetails);
                    });

                    busErpOrderDetailsService.saveBatch(busErpOrderDetailsList);
                }
                //busErpOrderService.removeById(one.getOrderId());

            }
        } else {
            List<SysCompany> companyList = busCwErpService.list(new QueryWrapper<SysCompany>().lambda().eq(SysCompany::getCompanyErpState, 1).eq(SysCompany::getCompanyId, hyDwCode));

            for (SysCompany busCwErp : companyList) {

                //销售
                if (orderType.equals(VoucherTypeEnum.Xs.getCode())) {
                    //long saleOrderCount = hyRemoteOrderService.saleOrderCount(busCwErp.getCompanyErpInstance(), currentDay);
                    //long count = busErpOrderDetailsService.count(new QueryWrapper<BusErpOrderDetails>().eq("date_format(createTime,'%Y-%m-%d')", currentDay).lambda().eq(BusErpOrderDetails::getHyDwCode, busCwErp.getCompanyCode()).eq(BusErpOrderDetails::getOrderType, VoucherTypeEnum.Xs.getCode()));
                    //海鹰有新订单继续
                    //if (saleOrderCount > count) {
                    if (true) {
                        //List<BusErpOrder> currentErpOrderList = busErpOrderService.list(new QueryWrapper<BusErpOrder>().lambda().between(BusErpOrder::getOrderDate, startDay, endDay).eq(BusErpOrder::getCompanyId, hyDwCode).eq(BusErpOrder::getOrderType, VoucherTypeEnum.Xs.getCode()));
                        //List<String> orderNos = currentErpOrderList.stream().map(BusErpOrder::getOrderNo).collect(Collectors.toList());
                        List<String> orderNos = new ArrayList<>();
                        List<EntityMap> list = hyRemoteOrderService.saleOrderList(busCwErp.getCompanyErpInstance(), startDay, endDay, CollUtil.isEmpty(orderNos) ? null : orderNos);
                        if (CollUtil.isNotEmpty(list)) {
                            List<BusErpOrder> busErpOrderList = new ArrayList<>();
                            list.forEach(item -> {
                                BusErpOrder busErpOrder = BeanUtil.fillBeanWithMap(item, new BusErpOrder(), false);
                                BusErpOrder check = busErpOrderService.findByOrderNoAndType(busErpOrder.getOrderNo(), orderType);
                                if (FlymeUtils.isNotEmpty(check)) {
                                    busErpOrder.setOrderId(check.getOrderId());
                                }
                                busErpOrder.setOrderType(VoucherTypeEnum.Xs.getCode());
                                busErpOrder.setErpDbName(busCwErp.getCompanyErpInstance());
                                busErpOrder.setHyDwCode(busCwErp.getCompanyCode());
                                busErpOrder.setCompanyId(busCwErp.getCompanyId());
                                busErpOrderList.add(busErpOrder);
                            });
                            orderNos = busErpOrderList.stream().map(BusErpOrder::getOrderNo).collect(Collectors.toList());
                            busErpOrderService.saveOrUpdateBatch(busErpOrderList);
                            busErpOrderDetailsService.remove(new QueryWrapper<BusErpOrderDetails>().lambda().in(BusErpOrderDetails::getOrderNo, orderNos).eq(BusErpOrderDetails::getOrderType, VoucherTypeEnum.Xs.getCode()));
                            List<EntityMap> orderDetailList = hyRemoteOrderService.saleOrderDetailList(busCwErp.getCompanyErpInstance(), null, busErpOrderList.stream().map(BusErpOrder::getOrderNo).collect(Collectors.toList()));
                            List<BusErpOrderDetails> busErpOrderDetailsList = new ArrayList<>();
                            orderDetailList.forEach(item -> {
                                BusErpOrderDetails busErpOrderDetails = BeanUtil.fillBeanWithMap(item, new BusErpOrderDetails(), false);
                                busErpOrderDetails.setOrderType(VoucherTypeEnum.Xs.getCode());
                                busErpOrderDetails.setOrderId(IdWorker.getIdStr());
                                busErpOrderDetails.setErpDbName(busCwErp.getCompanyErpInstance());
                                busErpOrderDetails.setHyDwCode(busCwErp.getCompanyCode());
                                busErpOrderDetails.setCompanyId(busCwErp.getCompanyId());
                                busErpOrderDetailsList.add(busErpOrderDetails);
                            });
                            busErpOrderDetailsService.saveBatch(busErpOrderDetailsList);
                        }
                    }
                }

                //    采购
                if (orderType.equals(VoucherTypeEnum.Cg.getCode())) {
                    //long buyOrderCount = hyRemoteOrderService.buyOrderCount(busCwErp.getCompanyErpInstance(), currentDay);
                    //long count = busErpOrderDetailsService.count(new QueryWrapper<BusErpOrderDetails>().eq("date_format(createTime,'%Y-%m-%d')", currentDay).lambda().eq(BusErpOrderDetails::getHyDwCode, busCwErp.getCompanyCode()).eq(BusErpOrderDetails::getOrderType, VoucherTypeEnum.Cg.getCode()));
                    //海鹰有新订单继续
                    //if (buyOrderCount > count) {
                    if (true) {
                        //List<BusErpOrder> currentErpOrderList = busErpOrderService.list(new QueryWrapper<BusErpOrder>().between("date_format(createTime,'%Y-%m-%d')", startDay, endDay).lambda().eq(BusErpOrder::getCompanyId, busCwErp.getCompanyId()).eq(BusErpOrder::getOrderType, VoucherTypeEnum.Cg.getCode()));
                        //List<String> orderNos = currentErpOrderList.stream().map(BusErpOrder::getOrderNo).collect(Collectors.toList());
                        List<String> orderNos = new ArrayList<>();

                        List<EntityMap> list = hyRemoteOrderService.buyOrderList(busCwErp.getCompanyErpInstance(), startDay, endDay, CollUtil.isEmpty(orderNos) ? null : orderNos);
                        if (CollUtil.isNotEmpty(list)) {

                            List<BusErpOrder> busErpOrderList = new ArrayList<>();
                            list.forEach(item -> {
                                BusErpOrder busErpOrder = BeanUtil.fillBeanWithMap(item, new BusErpOrder(), false);
                                BusErpOrder check = busErpOrderService.findByOrderNoAndType(busErpOrder.getOrderNo(), orderType);
                                if (FlymeUtils.isNotEmpty(check)) {
                                    busErpOrder.setOrderId(check.getOrderId());
                                }
                                busErpOrder.setOrderType(VoucherTypeEnum.Cg.getCode());
                                busErpOrder.setErpDbName(busCwErp.getCompanyErpInstance());
                                busErpOrder.setHyDwCode(busCwErp.getCompanyCode());
                                busErpOrder.setCompanyId(busCwErp.getCompanyId());
                                busErpOrderList.add(busErpOrder);
                            });
                            orderNos = busErpOrderList.stream().map(BusErpOrder::getOrderNo).collect(Collectors.toList());
                            busErpOrderService.saveOrUpdateBatch(busErpOrderList);
                            busErpOrderDetailsService.remove(new QueryWrapper<BusErpOrderDetails>().lambda().in(BusErpOrderDetails::getOrderNo, orderNos).eq(BusErpOrderDetails::getOrderType, orderType));
                            List<EntityMap> orderDetailList = hyRemoteOrderService.buyOrderDetailList(busCwErp.getCompanyErpInstance(), null, busErpOrderList.stream().map(BusErpOrder::getOrderNo).collect(Collectors.toList()));
                            List<BusErpOrderDetails> busErpOrderDetailsList = new ArrayList<>();
                            orderDetailList.forEach(item -> {
                                BusErpOrderDetails busErpOrderDetails = BeanUtil.fillBeanWithMap(item, new BusErpOrderDetails(), false);
                                busErpOrderDetails.setOrderType(VoucherTypeEnum.Cg.getCode());
                                busErpOrderDetails.setOrderId(IdWorker.getIdStr());
                                busErpOrderDetails.setErpDbName(busCwErp.getCompanyErpInstance());
                                busErpOrderDetails.setHyDwCode(busCwErp.getCompanyCode());
                                busErpOrderDetails.setCompanyId(busCwErp.getCompanyId());
                                busErpOrderDetailsList.add(busErpOrderDetails);
                            });

                            busErpOrderDetailsService.saveBatch(busErpOrderDetailsList);
                        }
                    }
                }
                //    成本
                if (orderType.equals(VoucherTypeEnum.Cb.getCode())) {
                    //long saleOrderCount = hyRemoteOrderService.saleCostCount(busCwErp.getCompanyErpInstance(), currentDay);
                    //long count = busErpOrderDetailsService.count(new QueryWrapper<BusErpOrderDetails>().eq("date_format(createTime,'%Y-%m-%d')", currentDay).lambda().eq(BusErpOrderDetails::getHyDwCode, busCwErp.getCompanyCode()).eq(BusErpOrderDetails::getOrderType, VoucherTypeEnum.Cb.getCode()));
                    //海鹰有新订单继续
                    //if (saleOrderCount > count) {
                    if (true) {
                        // List<BusErpOrder> currentErpOrderList = busErpOrderService.list(new QueryWrapper<BusErpOrder>().between("date_format(createTime,'%Y-%m-%d')", startDay, endDay).lambda().eq(BusErpOrder::getCompanyId, busCwErp.getCompanyId()).eq(BusErpOrder::getOrderType, VoucherTypeEnum.Cb.getCode()));
                        //List<String> orderNos = currentErpOrderList.stream().map(BusErpOrder::getOrderNo).collect(Collectors.toList());
                        List<String> orderNos = new ArrayList<>();
                        List<EntityMap> list = hyRemoteOrderService.saleCostList(busCwErp.getCompanyErpInstance(), startDay, endDay, CollUtil.isEmpty(orderNos) ? null : orderNos);
                        if (CollUtil.isNotEmpty(list)) {

                            List<BusErpOrder> busErpOrderList = new ArrayList<>();
                            list.forEach(item -> {
                                BusErpOrder busErpOrder = BeanUtil.fillBeanWithMap(item, new BusErpOrder(), false);
                                BusErpOrder check = busErpOrderService.findByOrderNoAndType(busErpOrder.getOrderNo(), VoucherTypeEnum.Cb.getCode());
                                if (FlymeUtils.isNotEmpty(check)) {
                                    busErpOrder.setOrderId(check.getOrderId());
                                }
                                busErpOrder.setOrderType(VoucherTypeEnum.Cb.getCode());
                                busErpOrder.setErpDbName(busCwErp.getCompanyErpInstance());
                                busErpOrder.setHyDwCode(busCwErp.getCompanyCode());
                                busErpOrder.setCompanyId(busCwErp.getCompanyId());
                                busErpOrderList.add(busErpOrder);
                            });
                            orderNos = busErpOrderList.stream().map(BusErpOrder::getOrderNo).collect(Collectors.toList());
                            busErpOrderService.saveOrUpdateBatch(busErpOrderList);
                            busErpOrderDetailsService.remove(new QueryWrapper<BusErpOrderDetails>().lambda().in(BusErpOrderDetails::getOrderNo, orderNos).eq(BusErpOrderDetails::getOrderType, VoucherTypeEnum.Cb.getCode()));
                            List<EntityMap> orderDetailList = hyRemoteOrderService.saleCostDetailList(busCwErp.getCompanyErpInstance(), null, busErpOrderList.stream().map(BusErpOrder::getOrderNo).collect(Collectors.toList()));
                            List<BusErpOrderDetails> busErpOrderDetailsList = new ArrayList<>();
                            orderDetailList.forEach(item -> {
                                BusErpOrderDetails busErpOrderDetails = BeanUtil.fillBeanWithMap(item, new BusErpOrderDetails(), false);
                                busErpOrderDetails.setOrderType(VoucherTypeEnum.Cb.getCode());
                                busErpOrderDetails.setOrderId(IdWorker.getIdStr());
                                busErpOrderDetails.setErpDbName(busCwErp.getCompanyErpInstance());
                                busErpOrderDetails.setHyDwCode(busCwErp.getCompanyCode());
                                busErpOrderDetails.setCompanyId(busCwErp.getCompanyId());
                                busErpOrderDetailsList.add(busErpOrderDetails);
                            });
                            busErpOrderDetailsService.saveBatch(busErpOrderDetailsList);
                        }

                    }
                }
                //    付款
                if (orderType.equals(VoucherTypeEnum.Fk.getCode())) {
                    List<BusErpOrderDetails> currentErpOrderList = busErpOrderDetailsService.list(new QueryWrapper<BusErpOrderDetails>().between("date_format(updateTime,'%Y-%m-%d')", startDay, endDay).lambda().eq(BusErpOrderDetails::getHyDwCode, busCwErp.getCompanyCode()).eq(BusErpOrderDetails::getOrderType, VoucherTypeEnum.Fk.getCode()));
                    List<String> orderNos = currentErpOrderList.stream().map(BusErpOrderDetails::getOrderNo).collect(Collectors.toList());
                    List<EntityMap> entityMaps = hyRemoteOrderService.receiptPaymentOrderList("-1", busCwErp.getCompanyErpInstance(), startDay, endDay, CollUtil.isEmpty(orderNos) ? null : orderNos);

                    Map<String, String> mxCollect = entityMaps.stream().filter(b -> ObjectUtil.isNotNull(b.get("mxNo"))).collect(Collectors.toMap(b -> b.get("orderNo").toString(), b -> b.get("mxNo").toString(), (v1, v2) -> v1));

                    if (CollUtil.isNotEmpty(entityMaps)) {
                        orderNos = entityMaps.stream().map(e -> e.get("orderNo").toString()).distinct().collect(Collectors.toList());
                        if (CollUtil.isEmpty(orderNos)) {
                            return;
                        }
                        Iterator<String> iterator = orderNos.stream().iterator();
                        //按单据勾对
                        List<String> orderNos1 = entityMaps.stream().filter(b -> ObjectUtil.isNull(b.get("mxNo"))).map(b -> b.get("orderNo").toString()).collect(Collectors.toList());
                        //明细勾对
                        List<String> orderNos2 = entityMaps.stream().filter(b -> ObjectUtil.isNotNull(b.get("mxNo"))).map(b -> b.get("orderNo").toString()).collect(Collectors.toList());
                        //while (iterator.hasNext()) {
                        for (int w = 0; w < orderNos.size(); w++) {
                            String orderNo11 = orderNos.get(w);
                            //String orderNo = iterator.next();
                            List<EntityMap> list = hyRemoteOrderService.purchasePaymentOrderList(busCwErp.getCompanyErpInstance(), null, Arrays.asList(orderNo11));
                            if (CollUtil.isEmpty(list)) {
                                return;
                            }
                            List<BusErpOrder> busErpOrderList = new ArrayList<>();
                            list.forEach(item -> {
                                BusErpOrder busErpOrder = BeanUtil.fillBeanWithMap(item, new BusErpOrder(), false);
                                busErpOrder.setOrderType(VoucherTypeEnum.Fk.getCode());
                                busErpOrder.setErpDbName(busCwErp.getCompanyErpInstance());
                                busErpOrder.setHyDwCode(busCwErp.getCompanyCode());
                                busErpOrder.setCreateTime(DateUtil.date());
                                busErpOrder.setCompanyId(busCwErp.getCompanyId());
                                busErpOrderList.add(busErpOrder);
                            });
                            busErpOrderService.saveBatch(busErpOrderList);
                            List<BusErpOrderDetails> busErpOrderDetailsList = new ArrayList<>();

                            if (orderNos1.contains(orderNo11)) {

                                //        t2.清单编码 orderNo,
                                List<EntityMap> orderDetailList = hyRemoteOrderService.purchasePaymentOrderDetailList(busCwErp.getCompanyErpInstance(), null, Arrays.asList(orderNo11));

                                Map<String, List<EntityMap>> detailList = entityMaps.stream().filter(b -> ObjectUtil.isNull(b.get("mxNo"))).collect(Collectors.groupingBy(b -> b.get("orderNo").toString()));

                                orderDetailList.forEach(item -> {

                                    BusErpOrderDetails busErpOrderDetails = BeanUtil.fillBeanWithMap(item, new BusErpOrderDetails(), false);
                                    if (CollUtil.isNotEmpty(detailList)) {
                                        for (String s : detailList.keySet()) {
                                            List<EntityMap> entityMaps1 = detailList.get(s);
                                            for (EntityMap entityMap : entityMaps1) {
                                                if (busErpOrderDetails.getOrderNo().equals(entityMap.get("orderNo"))) {
                                                    busErpOrderDetails.setUpdateTime(entityMap.get("receiptDate"));
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                    busErpOrderDetails.setOrderType(VoucherTypeEnum.Fk.getCode());
                                    busErpOrderDetails.setErpDbName(busCwErp.getCompanyErpInstance());
                                    busErpOrderDetails.setHyDwCode(busCwErp.getCompanyCode());
                                    busErpOrderDetails.setCreateTime(DateUtil.date());
                                    busErpOrderDetails.setCompanyId(busCwErp.getCompanyId());
                                    busErpOrderDetailsList.add(busErpOrderDetails);
                                });
                            }
                            if (orderNos2.contains(orderNo11)) {
                                String mxNo = mxCollect.get(orderNo11);
                                //按明细勾对
                                Map<String, String> proCollect = entityMaps.stream().filter(b -> ObjectUtil.isNotNull(b.get("mxNo"))).collect(Collectors.toMap(b -> b.get("productCode").toString() + "#" + b.get("productBatch").toString(), b -> b.get("productBatch").toString(), (v1, v2) -> v1));
                                List<EntityMap> orderDetailList3 = hyRemoteOrderService.purchasePaymentOrderDetailList(busCwErp.getCompanyErpInstance(), null, Arrays.asList(orderNo11));
                                orderDetailList3.forEach(item -> {


                                    BusErpOrderDetails busErpOrderDetails = BeanUtil.fillBeanWithMap(item, new BusErpOrderDetails(), false);
                                    String o = proCollect.get(busErpOrderDetails.getProductCode() + "#" + busErpOrderDetails.getProductBatch());
                                    if (StrUtil.isNotEmpty(o)) {
                                        //List<EntityMap> detailList = hyRemoteOrderService.purchasePaymentDetailList(busCwErp.getCompanyErpInstance(), mxNo, busErpOrderDetails.getProductCode(), busErpOrderDetails.getProductBatch());
                                        Map<String, List<EntityMap>> detailList = entityMaps.stream().filter(b -> ObjectUtil.isNotNull(b.get("mxNo"))).collect(Collectors.groupingBy(b -> b.get("mxNo").toString() + "#" + b.get("productCode").toString() + "#" + b.get("productBatch").toString()));
                                        if (CollUtil.isNotEmpty(detailList)) {
                                            for (String s : detailList.keySet()) {
                                                List<EntityMap> entityMaps1 = detailList.get(s);
                                                for (EntityMap entityMap : entityMaps1) {
                                                    //BigDecimal productPrice = entityMap.get("productPrice");
                                                    //int saleNum = entityMap.get("saleNum");
                                                    //BigDecimal saleAmount = entityMap.get("saleAmount");
                                                    //String productCode = entityMap.get("productCode");
                                                    //String productBatch = entityMap.get("productBatch");

                                                    //if (busErpOrderDetails.getProductCode().equals(productCode) && busErpOrderDetails.getProductBatch().equals(productBatch)) {
                                                    //    busErpOrderDetails.setProductPrice(productPrice);

                                                    if (busErpOrderDetails.getProductCode().equals(entityMap.get("productCode")) && busErpOrderDetails.getProductBatch().equals(entityMap.get("productBatch"))) {

                                                        BigDecimal saleAmount = entityMap.get("receiptAmount");
                                                        BigDecimal divide = saleAmount.divide(busErpOrderDetails.getProductPrice(), 2, BigDecimal.ROUND_HALF_UP);

                                                        busErpOrderService.update(new UpdateWrapper<BusErpOrder>().lambda().set(BusErpOrder::getUpdateTime, DateUtil.date()).set(BusErpOrder::getReceiptAmount, saleAmount).eq(BusErpOrder::getOrderType, VoucherTypeEnum.Fk.getCode()).eq(BusErpOrder::getOrderNo, entityMap.get("orderNo")));
                                                        busErpOrderDetails.setProductNum(divide.intValue());
                                                        busErpOrderDetails.setProductSaleAmount(saleAmount);
                                                        busErpOrderDetails.setUpdateTime(entityMap.get("receiptDate"));
                                                        break;
                                                    }
                                                    //}
                                                }
                                            }

                                        }
                                        busErpOrderDetails.setCreateTime(DateUtil.date());
                                        busErpOrderDetails.setOrderType(VoucherTypeEnum.Fk.getCode());
                                        busErpOrderDetails.setErpDbName(busCwErp.getCompanyErpInstance());
                                        busErpOrderDetails.setHyDwCode(busCwErp.getCompanyCode());
                                        busErpOrderDetailsList.add(busErpOrderDetails);
                                    }
                                });
                            }


                            busErpOrderDetailsService.saveBatch(busErpOrderDetailsList);

                        }
                    }
                }

                //    收款
                if (orderType.equals(VoucherTypeEnum.Sk.getCode())) {
                    List<BusErpOrderDetails> currentErpOrderList = busErpOrderDetailsService.list(new QueryWrapper<BusErpOrderDetails>().between("date_format(updateTime,'%Y-%m-%d')", startDay, endDay).lambda().eq(BusErpOrderDetails::getHyDwCode, busCwErp.getCompanyCode()).eq(BusErpOrderDetails::getOrderType, VoucherTypeEnum.Sk.getCode()));
                    List<String> orderNos = currentErpOrderList.stream().map(BusErpOrderDetails::getOrderNo).collect(Collectors.toList());

                    List<EntityMap> entityMaps = hyRemoteOrderService.receiptPaymentOrderList("1", busCwErp.getCompanyErpInstance(), startDay, endDay, CollUtil.isEmpty(orderNos) ? null : orderNos);


                    Map<String, String> mxCollect = entityMaps.stream().filter(b -> ObjectUtil.isNotNull(b.get("mxNo"))).collect(Collectors.toMap(b -> b.get("orderNo").toString(), b -> b.get("mxNo").toString(), (v1, v2) -> v1));

                    if (CollUtil.isEmpty(entityMaps)) {
                        return;
                    }
                    orderNos = entityMaps.stream().map(e -> e.get("orderNo").toString()).distinct().collect(Collectors.toList());
                    if (CollUtil.isEmpty(orderNos)) {
                        return;
                    }
                    //按单据勾对
                    List<String> orderNos1 = entityMaps.stream().filter(b -> ObjectUtil.isNull(b.get("mxNo"))).map(b -> b.get("orderNo").toString()).collect(Collectors.toList());
                    //明细勾对
                    List<String> orderNos2 = entityMaps.stream().filter(b -> ObjectUtil.isNotNull(b.get("mxNo"))).map(b -> b.get("orderNo").toString()).collect(Collectors.toList());
                    //while (iterator.hasNext()) {
                    for (int w = 0; w < orderNos.size(); w++) {
                        String orderNo11 = orderNos.get(w);
                        //String orderNo = iterator.next();
                        List<EntityMap> list = hyRemoteOrderService.purchasePayableOrderList(busCwErp.getCompanyErpInstance(), null, Arrays.asList(orderNo11));
                        if (CollUtil.isEmpty(list)) {
                            return;
                        }
                        List<BusErpOrder> busErpOrderList = new ArrayList<>();
                        list.forEach(item -> {
                            BusErpOrder busErpOrder = BeanUtil.fillBeanWithMap(item, new BusErpOrder(), false);
                            busErpOrder.setOrderType(VoucherTypeEnum.Sk.getCode());
                            busErpOrder.setErpDbName(busCwErp.getCompanyErpInstance());
                            busErpOrder.setHyDwCode(busCwErp.getCompanyCode());
                            busErpOrder.setCreateTime(DateUtil.date());
                            busErpOrder.setCompanyId(busCwErp.getCompanyId());
                            busErpOrderList.add(busErpOrder);
                        });
                        busErpOrderService.saveBatch(busErpOrderList);
                        List<BusErpOrderDetails> busErpOrderDetailsList = new ArrayList<>();

                        if (orderNos1.contains(orderNo11)) {
                            Map<String, List<EntityMap>> detailList = entityMaps.stream().filter(b -> ObjectUtil.isNull(b.get("mxNo"))).collect(Collectors.groupingBy(b -> b.get("orderNo").toString()));

                            List<EntityMap> orderDetailList = hyRemoteOrderService.purchasePayableOrderDetailList(busCwErp.getCompanyErpInstance(), null, Arrays.asList(orderNo11));
                            orderDetailList.forEach(item -> {
                                BusErpOrderDetails busErpOrderDetails = BeanUtil.fillBeanWithMap(item, new BusErpOrderDetails(), false);
                                busErpOrderDetails.setOrderType(VoucherTypeEnum.Sk.getCode());
                                busErpOrderDetails.setErpDbName(busCwErp.getCompanyErpInstance());
                                busErpOrderDetails.setHyDwCode(busCwErp.getCompanyCode());
                                busErpOrderDetails.setCreateTime(DateUtil.date());
                                if (CollUtil.isNotEmpty(detailList)) {
                                    for (String s : detailList.keySet()) {
                                        List<EntityMap> entityMaps1 = detailList.get(s);
                                        for (EntityMap entityMap : entityMaps1) {
                                            if (busErpOrderDetails.getOrderNo().equals(entityMap.get("orderNo"))) {
                                                busErpOrderDetails.setUpdateTime(entityMap.get("receiptDate"));
                                                break;
                                            }
                                        }
                                    }
                                }
                                busErpOrderDetailsList.add(busErpOrderDetails);
                            });
                        }
                        if (orderNos2.contains(orderNo11)) {
                            String mxNo = mxCollect.get(orderNo11);
                            //按明细勾对
                            Map<String, String> proCollect = entityMaps.stream().filter(b -> ObjectUtil.isNotNull(b.get("mxNo"))).collect(Collectors.toMap(b -> b.get("productCode").toString() + "#" + b.get("productBatch").toString(), b -> b.get("productBatch").toString(), (v1, v2) -> v1));
                            List<EntityMap> orderDetailList3 = hyRemoteOrderService.purchasePayableOrderDetailList(busCwErp.getCompanyErpInstance(), null, Arrays.asList(orderNo11));
                            orderDetailList3.forEach(item -> {


                                BusErpOrderDetails busErpOrderDetails = BeanUtil.fillBeanWithMap(item, new BusErpOrderDetails(), false);
                                String o = proCollect.get(busErpOrderDetails.getProductCode() + "#" + busErpOrderDetails.getProductBatch());
                                if (StrUtil.isNotEmpty(o)) {
                                    //List<EntityMap> detailList = hyRemoteOrderService.purchasePaymentDetailList(busCwErp.getCompanyErpInstance(), mxNo, busErpOrderDetails.getProductCode(), busErpOrderDetails.getProductBatch());
                                    Map<String, List<EntityMap>> detailList = entityMaps.stream().filter(b -> ObjectUtil.isNotNull(b.get("mxNo"))).collect(Collectors.groupingBy(b -> b.get("mxNo").toString() + "#" + b.get("productCode").toString() + "#" + b.get("productBatch").toString()));
                                    if (CollUtil.isNotEmpty(detailList)) {
                                        for (String s : detailList.keySet()) {
                                            List<EntityMap> entityMaps1 = detailList.get(s);
                                            for (EntityMap entityMap : entityMaps1) {
                                                //BigDecimal productPrice = entityMap.get("productPrice");
                                                //int saleNum = entityMap.get("saleNum");
                                                //BigDecimal saleAmount = entityMap.get("saleAmount");
                                                //String productCode = entityMap.get("productCode");
                                                //String productBatch = entityMap.get("productBatch");

                                                //if (busErpOrderDetails.getProductCode().equals(productCode) && busErpOrderDetails.getProductBatch().equals(productBatch)) {
                                                //    busErpOrderDetails.setProductPrice(productPrice);

                                                if (busErpOrderDetails.getProductCode().equals(entityMap.get("productCode")) && busErpOrderDetails.getProductBatch().equals(entityMap.get("productBatch"))) {

                                                    BigDecimal saleAmount = entityMap.get("receiptAmount");
                                                    BigDecimal divide = saleAmount.divide(busErpOrderDetails.getProductPrice(), 2, BigDecimal.ROUND_HALF_UP);

                                                    busErpOrderService.update(new UpdateWrapper<BusErpOrder>().lambda().set(BusErpOrder::getReceiptAmount, saleAmount).eq(BusErpOrder::getOrderType, VoucherTypeEnum.Sk.getCode()).eq(BusErpOrder::getOrderNo, entityMap.get("orderNo")));
                                                    busErpOrderDetails.setProductNum(divide.intValue());
                                                    busErpOrderDetails.setProductSaleAmount(saleAmount);
                                                    busErpOrderDetails.setUpdateTime(entityMap.get("receiptDate"));

                                                    break;
                                                }
                                                //}
                                            }
                                        }

                                    }
                                    busErpOrderDetails.setCreateTime(DateUtil.date());
                                    busErpOrderDetails.setOrderType(VoucherTypeEnum.Sk.getCode());
                                    busErpOrderDetails.setErpDbName(busCwErp.getCompanyErpInstance());
                                    busErpOrderDetails.setHyDwCode(busCwErp.getCompanyCode());
                                    busErpOrderDetailsList.add(busErpOrderDetails);
                                }
                            });
                        }


                        busErpOrderDetailsService.saveBatch(busErpOrderDetailsList);


                    }

                }
            }
        }
    }

    /**
     * 过滤非数字
     *
     * @param str
     * @return
     */
    public static String getNumeric(String str) {
        String regEx = "[^0-9]";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(str);
        return m.replaceAll("").trim();
    }

    public static void main(String[] args) {
        System.out.println("00030000021968".length());

        String s = "{\"voucherHead\":{\"ZWPZK_ID\":\"\",\"ZWPZK_DWBH\":\"01001\",\"ZWPZK_PZNM\":\"\",\"ZWPZK_KJND\":\"2023\",\"ZWPZK_KJQJ\":\" 5\",\"ZWPZK_PZRQ\":\"20230510\",\"ZWPZK_PZBH\":\"\",\"ZWPZK_LXBH\":\"01\",\"ZWPZK_FJZS\":0,\"ZWPZK_TYPE\":\"0\",\"ZWPZK_ZDR\":\"\",\"ZWPZK_PZR\":\"\",\"ZWPZK_FHR\":\"\",\"ZWPZK_JZR\":\"\",\"ZWPZK_CN\":\"\",\"ZWPZK_KJZG\":\"\",\"ZWPZK_FHF\":\"1\",\"ZWPZK_JZF\":\"1\",\"ZWPZK_WZF\":\"1\",\"ZWPZK_ZFF\":\"0\",\"ZWPZK_PZZT\":\"1\",\"ZWPZK_YRJKLB\":\"\",\"ZWPZK_TZDZS\":0,\"ZWPZK_ZDBZ\":\"0\",\"SysUserID\":\"\",\"ZWPZK_JBR\":\"\",\"voucherfl\":[{\"ZWPZFL_ID\":\"\",\"ZWPZK_ID\":\"\",\"ZWPZFL_DWBH\":\"01001\",\"ZWPZFL_PZNM\":\"\",\"ZWPZFL_FLNM\":\"0001\",\"ZWPZFL_FLBH\":\"0001\",\"ZWPZFL_KMBH\":\"10020301\",\"ZWPZFL_JSFS\":\"\",\"ZWPZFL_ZY\":\"1.内部转账\",\"ZWPZFL_JFJE\":10,\"ZWPZFL_DFJE\":10,\"ZWPZFL_SL\":1,\"ZWPZFL_DJ\":10,\"ZWPZFL_WB\":-10,\"ZWPZFL_HL\":1,\"ZWPZFL_JZFX\":\"1\",\"ZWPZFL_JSH\":\"\",\"ZWPZFL_YWRQ\":\"20230510\",\"ZWPZFL_WBBH\":\"01\",\"ZWPZFL_YHDZ\":\"0\",\"ZWPZFL_ReadOnly\":\"\",\"voucherfzhs\":[{\"ZWFZYS_ID\":\"\",\"ZWFZYS_FLID\":\"\",\"ZWFZYS_DWBH\":\"01001\",\"ZWFZYS_PZNM\":\"\",\"ZWFZYS_FLNM\":\"\",\"ZWFZYS_YSBH\":\"0001\",\"ZWFZYS_KMBH\":\"10020201\",\"ZWFZYS_BMBH\":\"0101\",\"ZWFZYS_WLDWBH\":\"019999\",\"ZWFZYS_ZGBH\":\"\",\"ZWFZYS_CPBH\":\"\",\"ZWFZYS_XMBH\":\"000027\",\"ZWFZYS_WBBH\":\"01\",\"ZWFZYS_JZFX\":\"1\",\"ZWFZYS_SL\":1,\"ZWFZYS_DJ\":10,\"ZWFZYS_WB\":-10,\"ZWFZYS_HL\":1,\"ZWFZYS_JE\":10,\"ZWFZYS_YWRQ\":\"20230510\",\"ZWFZYS_YWH\":\"\",\"ZWFZYS_PJH\":\"\",\"ZWFZYS_DWDZ\":\"0\",\"ZWFZYS_SJ01\":\"\",\"ZWFZYS_SJ02\":\"\",\"ZWFZYS_SJ03\":\"\",\"ZWFZYS_SJ04\":\"\",\"ZWFZYS_SJ05\":\"\",\"ZWFZYS_SM01\":\"\",\"ZWFZYS_SM02\":\"\",\"ZWFZYS_SM03\":\"\",\"ZWFZYS_SM04\":\"\",\"ZWFZYS_SM05\":\"\",\"ZWFZYS_SM06\":\"\",\"ZWFZYS_SM07\":\"\",\"ZWFZYS_SM08\":\"\",\"ZWFZYS_SM09\":\"\",\"ZWFZYS_SM10\":\"\",\"ZWFZYS_JSFS\":\"\",\"ZWFZYS_JSH\":\"\",\"ZWFZYS_YT\":\"1内部转账\",\"ZWFZYS_YHDZ\":\"0\",\"ZWFZYS_JSRQ\":\"20230510\"}]},{\"ZWPZFL_ID\":\"\",\"ZWPZK_ID\":\"\",\"ZWPZFL_DWBH\":\"01001\",\"ZWPZFL_PZNM\":\"\",\"ZWPZFL_FLNM\":\"0002\",\"ZWPZFL_FLBH\":\"0002\",\"ZWPZFL_KMBH\":\"10020301\",\"ZWPZFL_JSFS\":\"\",\"ZWPZFL_ZY\":\"1.内部转账\",\"ZWPZFL_JFJE\":10,\"ZWPZFL_DFJE\":10,\"ZWPZFL_SL\":1,\"ZWPZFL_DJ\":10,\"ZWPZFL_WB\":-10,\"ZWPZFL_HL\":1,\"ZWPZFL_JZFX\":\"2\",\"ZWPZFL_JSH\":\"\",\"ZWPZFL_YWRQ\":\"20230510\",\"ZWPZFL_WBBH\":\"01\",\"ZWPZFL_YHDZ\":\"0\",\"ZWPZFL_ReadOnly\":\"\",\"voucherfzhs\":[{\"ZWFZYS_ID\":\"\",\"ZWFZYS_FLID\":\"\",\"ZWFZYS_DWBH\":\"01001\",\"ZWFZYS_PZNM\":\"\",\"ZWFZYS_FLNM\":\"\",\"ZWFZYS_YSBH\":\"0001\",\"ZWFZYS_KMBH\":\"10020201\",\"ZWFZYS_BMBH\":\"0101\",\"ZWFZYS_WLDWBH\":\"019999\",\"ZWFZYS_ZGBH\":\"\",\"ZWFZYS_CPBH\":\"\",\"ZWFZYS_XMBH\":\"000027\",\"ZWFZYS_WBBH\":\"01\",\"ZWFZYS_JZFX\":\"1\",\"ZWFZYS_SL\":1,\"ZWFZYS_DJ\":10,\"ZWFZYS_WB\":-10,\"ZWFZYS_HL\":1,\"ZWFZYS_JE\":10,\"ZWFZYS_YWRQ\":\"20230510\",\"ZWFZYS_YWH\":\"\",\"ZWFZYS_PJH\":\"\",\"ZWFZYS_DWDZ\":\"0\",\"ZWFZYS_SJ01\":\"\",\"ZWFZYS_SJ02\":\"\",\"ZWFZYS_SJ03\":\"\",\"ZWFZYS_SJ04\":\"\",\"ZWFZYS_SJ05\":\"\",\"ZWFZYS_SM01\":\"\",\"ZWFZYS_SM02\":\"\",\"ZWFZYS_SM03\":\"\",\"ZWFZYS_SM04\":\"\",\"ZWFZYS_SM05\":\"\",\"ZWFZYS_SM06\":\"\",\"ZWFZYS_SM07\":\"\",\"ZWFZYS_SM08\":\"\",\"ZWFZYS_SM09\":\"\",\"ZWFZYS_SM10\":\"\",\"ZWFZYS_JSFS\":\"\",\"ZWFZYS_JSH\":\"\",\"ZWFZYS_YT\":\"2内部转账\",\"ZWFZYS_YHDZ\":\"0\",\"ZWFZYS_JSRQ\":\"20230510\"}]}]}}";


        String url = "http://8.142.97.38:8211/cwbase/api/GS7VoucherGenerateHandler.ashx";

        //String result = HttpUtil.post(url, s);
        //System.out.println(s);
        //System.out.println(result);
        BusErpOrderDetails details = new BusErpOrderDetails();

        details.setProductNum(29813);
        details.setProductSaleAmount(new BigDecimal("209974.96"));
        System.out.println();
    }
}